Unity 2017.1.0f3: keeping 3D objects throughout multiple scenes

I am writing an Android App which allows users to DIY their phone cases and then export them to .stl/other 3D printing format. I would try to make my words as short as possible.

I have several scenes(each scene has a button for switching to next scene):

Scene 0(Start Scene): A simple start menu with an exit button and a start button(canvas with an image as a background).

Scene 1(Model Scene): 3 buttons(allows users to choose 3 kinds of models: iphone7, iphone6s, LGG6). After pressing one of the button, the corresponding phone case will be displayed to the users.

Scene 2(Color Scene): there are several colors for users to choose. After touching a color button, the material of the phone case will be changed to the corresponding color. Users can instantly preview how the case looks like.

Scene 3(Pattern Scene): there are several patterns for users to choose. After touching a pattern button, the back of the phone case will be changed to the corresponding pattern. Users can instantly preview how the case looks like.

…And there will be a few more scenes which add more things/functions to the phone case.

Scene x(exporting): Exporting the phone case to 3D printing format.

I’ve encountered a few problems when I am coding.

The main problem is that I need to keep the chosen phone case(a 3D object) throughout all the scenes. In details, after users have chosen the wanted phone case(lets say LGG6) in scene1, the case need to be kept and passed to the next scene(scene2:color scene) for further editting. After coloring the case in scene2, the colored phone case will then be passed to the next scene(pattern scene) for editting the pattern and so on.

I keep on surfing the net these days and I find several ways which can achieve this. I decided to use “DontDestroyOnLoad”. However, there is something I dont understand:

I created a game object called “AppManager” in scene 0. There is a C# script(also called “AppManager” attached to it. Inside it, I created a lot of variables to store all kind of elements needed in all scenes, including Canvas&UI elements, 3D object(3 type of phone cases, I stored them in Render Type), cameras, directional light, and also the functions I need.

Then, I implement a “DontDestroyOnLoad” function inside the script.

Also, I made all UI elements, 3D objects, cameras as the children of “AppManager”

I would like to ask:

  1. Am I using “DontDestroyOnLoad”
    correctly? I still dont understand
    how can I access the variables and
    functions stored in
    “AppManager”(scene 0) from other
    scenes.
  2. Since I have several scenes which
    have some unique buttons other
    scenes dont require, I hope I can
    active the
    function(.gameObject.SetActive
    (true/false)) of specific UI
    elements in each scene
    and disable
    those I dont need
    . I would like to
    know if I can implement this
    function inside my “AppManager”? Or
    in each scene, I need to create an
    unique script to enable/disable
    these UI elements?
  3. I would like to implement a “back”
    button
    in scene 2, 3, 4,… What
    does it mean? Lets say the user is
    now in scene 3(pattern scene). He
    has chosen LGG6 case model and red
    color(material). But he wants to
    modify the color, altering from red
    to black. Then, there is a back
    button in scene 3 for him to go back
    to scene 2 to choose the color. That
    means my app need to undo the color
    change. I would like to ask if there
    is a function in unity which can
    save all the information in a
    current scene and can be reloaded
    later?

I am not sure if I have made my problem clear enough. If you want more details, just feel free to ask. Since I have been struggling to solve these problems for nearly a week(I am too stupid lol), I hope that someone can give me a help. Thank you!

Here’s my humble opinion.

  1. I don’t think you are using DontDestroyOnLoad correctly and that’s only because of what you really want it for. You said:

The main problem is that I need to keep the chosen phone case(a 3D object) throughout all the scenes

Right? So you want this specific data, a chosen 3D object to be known in all scenes. That’s the only piece of information you really need to share through all scenes. However you created the app manager which handles UI and other stuff that is scene specific. To me it doesn’t make sense to use DontDestroyOnLoad on an object that deals with data that shouldn’t be shared with other scenes, like UI.

  1. Yes, you could implement the SetActive method inside your app manager, you could also have it implemented in a separate script that is scene specific.

With that being said I don’t think you should do that. What I think you should do is separation of concerns, let the app manager or maybe some other new object only do the work of sharing the data between scenes, that is having DontDestroyOnLoad and a field with the chosen 3D case and have the other one manage the UI specific to that scene. Having an object that travels through scenes holding all the UI that exists in your app is not an advisable thing to do memory wise, and it also defeats the point of even having scenes.

  1. Yes, there’s a class called PlayerPrefs that contains methods that allow you to save ints, floats and strings that are persistent, which means that even the information will remain even if you close and open the app again. That’s the easiest way to save data, there are other ways to have persistent data but those imply the use of serialization which is extra work.

With respect to the third point, maybe you shouldn’t have different scenes for that? If scene 2,3,4 are just about choosing an option then why not have those options in one scene, just have different UI be activated and deactivated to show the appropriate option screen.

And that’s it. If you have any questions, suggestions or complains, I’m all ears.

Another option is using the scenemanager. You can keep the objects that you want to keep in a scene that you never unload.