- Home /
Networking LoadLevel - player connect
I've got a lot of my networking platform in place at the moment, but when setting up my NPC/Enemy to take syncd damage (by adding a networkview component and RPC'ing the damage as per the player script) I have noticed that the enemy is reloaded for player 2. This is indicated by damage being dealt by player 1 before player 2 joins, and the enemy being at full health when player 2 joins - damage inflicted after this affects both.
I think this is because the level is being loaded for player 2 rather than "joined" - how do I have player 2 "the client" join the scene created by player 1 "the server"?
Side question: is my approach to NPCs/Enemies the correct one?
Cheers
Edit: As per comment:
void OnConnectedToServer(){
SpawnPlayer ();
}
private void SpawnPlayer(){
Application.LoadLevel (1);
GameObject player = Network.Instantiate (playerPrefab, new Vector3 (0, 0.2f, 0), Quaternion.identity, 0) as GameObject;
player.GetComponent<Player> ().PlayerName = playerName;
}
This is also called in OnServerInitialized();
Answer by Ibzy · Jul 02, 2015 at 06:20 PM
With the new UNET functionality I can now simply spawn the enemy once as the server, and then new players just see them. Simple :)
You know responding on dead threads is depreciated right? Along with accepting your own answer. (That's a little more forgivable :P )
However this should help some other people. So, answer is appreciated. $$anonymous$$aking my comment rather redundant.
Answer by FirePlantGames · Dec 19, 2014 at 02:28 AM
Use RPCMode.AllBuffered this adds the RPC to the buffer(the buffer is loaded when the player joins the server)
I already have it set to AllBuffered, its as though the whole scene, including the enemy, is recreated for player 2 so its a mew enemy which receives both RPCs?
Oh, I see what you mean now, yeah, state synchronization is a real pain. It's a problem with networkView id's, could you share you instantiation code?
Only instantiation code is for the Player (added above) - I tried one for the enemy and a new one got instantiated as player 2 joined. This use a separate "level master" script to Network.instantiate() on Start(). I'm thinking I need to use OnServerInitialized(), but I want this game to consist of many scenes not necessarily inhabited by all players at the same time, rather than it all on one scene?
Okay, so what happens is this; 1. You connect and Everything From the server is loaded into the current Scene. 2. You then load a completely new scene thusly removing all of the networks objects and leaving them in the old scene. 3. Solution: I'm working on it :/ I will come up with one, and I already have a concept down, I just have to test it.
That's exactly what's happening, except the object in scene 1 is still there for player 1 and a new version is created for player 2 but they are then linked. Its definitely a matter of having my players "join" I just cant see any reference to it anywhere.
Your answer
Follow this Question
Related Questions
Client not loading into the same scene as host 0 Answers
Networking Help Needed 0 Answers
Networking - 2 Scenes where one i selection and other actual game 2 Answers
How to load online level 2 Answers
Unity networking tutorial? 6 Answers