Search Unity

More Than One Spawn Point In Scene?

Discussion in 'Scripting' started by Don-Gray, Aug 23, 2009.

  1. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    I assume this is no problem with a script.
    I would like the game to start in my first scene at one point, then to have the player move to another scene from another area in the starting scene, then be able to come back from that scene at that point so it seems to the player they are in a single scene, but I can save on scene overload.
     
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    I'm not clear on your exact question as the wording is, well, a little odd to me... :p

    Yes, you can have behavior where the player moves between scenes/levels, entering/exiting at specific points (doors for example) so that it gives that feeling of all one level. Just keep in mind that you may need to make use of DontDestroyOnLoad to keep some objects in memory.


    Let me know if I'm on track in the slightest and if not offer some course correction. :)
     
  3. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    I think putting the last phrase ("but I can save on scene overload.") on the end of my statement creates some confusion.
    That statement is referring to saving on scene overload, while the whole rest is referring to what I want to do to save on scene overload (too much drain on the user's system resources).
    I assumed it was possible but was just trying to get some confirmation while waiting for my scripting guy to get back to work on my scripts.

    What objects will need to be kept memory?
    Is this necessary in order to have the player spawn back in a separate place other than the original starting location in the first scene?

    Thanks for the response.
     
  4. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Those questions can be answered in any number of ways depending on how you want to construct your game. For example:

    1. You could always have your player persist, its never destroyed on scene/level load. Your player object has a small data chunk associated with it that stores the "respawn" points to be used in any/all levels of interest. If no respawn point is found for the current level, then you use the default starting point. If one is found, then you jump them there right away.

    2. You could have a "game manager" object that persists, its never destroyed on scene/level load. Your player object is then created on scene load and the first thing it does is ask the manager "where do I start on this level?", if no data is stored you go to the default location, if some data is found then that indicates the respawn point to use instead.

    3. You could flush all necessary data out to disk via the PlayerPreferences class, then unload everything with every scene/level load. On load, your player/manager/whatever reads in the player prefs data to look for any "last respawn point" data, if found use it, if not use defaults. Then of course before leaving any scene/level that same data must be written out via PlayerPrefs.


    And I'm sure there are yet even more flavors, but I hope the point is coming across that it's up to you and how you want to structure your project and data storage. :)


    Does that help or hurt? Hopefully help! Let us know as we're here to help. :)
     
  5. Don-Gray

    Don-Gray

    Joined:
    Mar 18, 2009
    Posts:
    2,278
    Lots of possibilities it seems.
    It would really hurt for me to try to implement them but I will have some options for the scripting guy if he asks or can ask him what the implications are for using any of them.

    Thanks!