here is what i can’t understand in this case: when two player play, one connects and then the other one connects: whats happening is that instead of spawning a car for user 2, it just shows user 2 what user 1 is doing instead. and user 2 has no control over anything basically in that scene since only one car was spawned and belonged to user 1. so how am i supposed to fix that
Hey, don’t forget that when a prefab is replicated to clients all the components are replicated too, so some behaviours you need to disable on the replicated one or they will operate on all clients when you really just want them to operate on the authority. This is described here: Prefab setup | coherence Documentation
You probably need to disable your camera and the controller you’re using on your cars when the prefab is replicated.
I recommend stepping back from your project a bit and running through the coherence tutorials to really understand the nature of making multiplayer games and how coherence makes some of these complex concepts easy: Samples and tutorials | coherence Documentation
no, even normally in the 7_playerspawner scene, it encounters the same issue. whereas: when user 1 connects, then user 2 connects, user 2 does not have a player to control but user 2 can see what user 1 is doing, user 1 has control over his player because it was spawned, if you want to visually really see it, then I can send a video for what is happening.
vid:
.
please reply please.!..!
absolutely going in the wrong direction , can’t wait to complain without a reply.
will complain pretty soon!
Hey Muhammad, sorry for the delay in replying. This thread slipped off my mind.
We actually realised there’s a small bug in the sample scene, which could lead to unexpected behaviour. So I went in and fixed it, that’s why it took me a bit longer.
Because the new version of this sample will probably be included in our upcoming release (1.4.0, probably), it might take some time… but I think you need it now, so I put it into a .zip file so you can explore it now:
Download: Package Samples 1.4.0 Preview
I want to mention though that, bug aside, the logic is kinda similar. I’ll re-explain here using the class names in the sample scene:
- There’s a network entity in the scene called SpawnManager.
- There are a bunch of spawn points. These are not networked. The SpawnManager knows about them (has them in a pre-populated list).
- First player to connect takes control of it. This player is the one to assign spawn points.
- They immediately create a player for themselves, using the method described below, by messaging their own ClientConnection:
AssignSpawnPointToClient(coherenceBridge.ClientConnections.GetMine()); // For this Client
- This player relies on ClientConnections to assign spawn points:
coherenceBridge.ClientConnections.OnCreated += AssignSpawnPointToClient; // For future Clients
So as soon as a new CC is created, it messages it with the spawn point position:
private void AssignSpawnPointToClient(CoherenceClientConnection clientConnection)
{
clientConnection.SendClientMessage<Client>(nameof(Client.SpawnPlayer), MessageTarget.AuthorityOnly, spawnPosition);
}
- The ClientConnection Prefab of the other player who just connected receives the message, and creates a character for themselves at the position sent by the first player:
[Command]
public void SpawnPlayer(Vector3 spawnPosition) { ... }
So again: PlayerSpawner > sees ClientConnection, messages it > (on the remote client) ClientConnection Prefab receives message > Spawns its own player at position
If this is still unclear, I would strongly suggest to familiarise yourself with ClientConnections on their own first.
Hope it helps.
Oh well, i need access to the file. Also i need a bit more details about the client connections like which function to put it in (e.g. void Start(){} etc…)
so maybe i can figure out some ways myself but would be great if you could help a bit more
My bad, it’s accessible now.
If you look in the code for that scene, it’s pretty compact so you should be able to identify where the events I mentioned are.
Ok i will see this, now lets see if its accessible
So it seems there is a totally different problem with the scene now: it just shows a debug that it has connected succesfully to the repliction server but does not instantiate a player for them.
well i still think we won’t get this solved now, maybe some few days later.
I think at this point one good way to do this is if you make a video of the whole setup? It doesn’t need voice, just show all of the Prefabs configuration and what the scripts do? Then I can take a look.
(you can’t share it here, but you can upload it on YouTube as unlisted)
I suspect there’s something wrong in the setup that’s messing your game up.
Thanks, I will make the video. Don’t worry just give like an hour and it will be done
Here is the link to the video: https://www.youtube.com/watch?v=6beutP8TeRs
Hello please reply i have waited long enough!
Hi. Please understand that we don’t work on the weekend.
Regarding your video. It’s clearly showing that the PlayerSpawner Prefab is missing a script. Why not starting from fixing that?
Oh well that happened maybe inside the samples 1.4.0 so I have no idea which script is missing from its reference.
Well I went up in the old sample with the bug and the script that I guess that is missing is the PlayerSpawner.cs file
I see.
But then, so what’s the PlayerSpawner that you have in your car scene? That has no missing script?
And why is there two spawners, one inside the other?
oh well those were my own experiments, the original one is the prefab. the one inside it is my own manager which has a script that is deactivated. so now what else?