Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

scene and object persistence

Discussion in 'Scripting' started by DirtyBlasion, Nov 23, 2016.

  1. DirtyBlasion

    DirtyBlasion

    Joined:
    Aug 21, 2016
    Posts:
    31
    So I want to start making a 2d rpg. Ok, but there are coming the hard questions.

    I should use c#(I dont care if your example script is java script or c#, I understand both, but I prefer c#). I was planing to use dontdestroyonload(), but there are coming the best parts....

    dontdestroyonload() will mentain the same values for the object in every scene? Or not?

    A good example is gamemaker's persistence, I like that style of room persistence. And GameObject persistente(follow you in every room, and keep the values???).

    I want to work with some thousands(Idk, if I spell it good) of scenes.


    PS1: Im a medium c# user and java script begginer. I didnt worked to much with object oriented, all I did with c# was some command projects. My single project with object oriented was a self learning talking AI, but it was buggy.
    PS2: Sorry about my english, all I know is from youtube and games, no gramar learned ever(not really "no gramar" some verbs and some basic rules)
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    yes, objects that have a script with that on them persist between scene changes.

    Note this means their "lifecycle" is different from other objects so creating references to things in the current scene has to be handled differently to non persistent objects.

    the advice I've seen previously (from other people who actually make games around here :) o_O ) is to have an initial scene which instantiates the persisting objects (like high level gamemanager scripts or whatever) and then load other scenes from there without returning to that scene. It'll stop multiple instances being loaded, a common initial issue is people instantiating a persistent object in the "main menu" and then returning to that scene when the player loses... instantiating a second persistent object...