Having a problem with player respawning when chaning levels

Options
I made some commands players can enter into my chat. To load a different level. It loads the level but deletes the player and doesn't re-instantiate him when the level changes. How am I supposed to properly do this? More detailed post about it is here.

http://answers.unity3d.com/questions/60 ... ent-613147

Thanks in advance.

Comments

  • Tobias
    Options
    It depends on what you want to achieve.
    I guess you want to keep the avatar? GOs do get destroyed by loading a scene. That's not a network issue exactly. Marking it as "DontDestroyOnLoad" could help. Or you can just re-instantiate it on load.
    Keep in mind that all your players need to load the same scene, or else network IDs (in PhotonViews) won't target the same objects in the scene.
  • cj31387
    Options
    Yeah I want to re-instantiate on load but whats the function for that? To check when a level is done loading?
  • cj31387
    Options
    I did a static bool to re-instantiate the player but yeah I'm getting the problem of what you said about the network ids not targeting objects in the scene. Because my chat doesn't show up for the player after a level loaded. How would I fix this? Thanks.
  • Tobias
    Options
    You know that all characters get destroyed when a player loads a new scene. You are re-creating the one this client wants to use but how about the other user's characters?
    You need to either make sure they don't get destroyed or you have to re-instantiate them as well once you loaded.

    Are you loading different scenes, even though the players are in the same room?
    I don't know fully what you need to achieve. Maybe you explain.
  • cj31387
    Options
    Yeah I need to know if there is a OnNewLoadedScene() function or something that is like OnJoinedRoom() but for when a rooms level changes. If not how can I know when to re-instantiate the player after the scene loads? Currently what I have setup is. The player starts a game it randomly creates a room and game for him, its set to a specific scene, scene 0. When the player types in his chatbox this exact string "/level 1" or "/level 2" or "/level 0" it will change the level to that level. It works but the player doesn't get automatically re-instantiated. If i DontDestroyOnLoad() he does go into the next scene but the chat disapears and his placement in the level is wierd. he doesnt move to a spawn point. Which brings me back to again, is there a command that is run when a new scene is loaded that is like OnJoinedRoom() so I can put my respawn code there and place him on a spawn point.
  • Tobias
    Options
    Unity provides a callback when a level was loaded. Don't know the exact name right now but you find it easily in the scripting reference.
    Aside from that: All Start() methods are called for all the objects you have in a loaded scene, too.
  • cj31387
    Options
    Yeah I was thinking it was going to be a photon method. But I did try re-instantiating in start but it didn't work out right. I'll try again.
  • cj31387
    Options
    Ok thanks unity's OnLevelWasLoaded(int) did the job. Just need to test with another player now. Thanks!