I have 2 scenes. The player object is set to not be destroyed when a new scene loads. I can move the player from the starting scene to the next scene just fine, it works perfectly (except a minor flash between scenes resulting from no loading screen). When I try to move back, I get an audio listener error (because there are too many). To fix this, I tried turning the player object into a prefab and removing the player object from the first scene. Then I setup an empty game object and matched its transform to what the player object should start at and setup a short script to instantiate the player prefab on the empty game object. That all works fine, except for one thing. All of my scripts freak out with null excepts when doing it this way.
I could be wrong about this, but it seems when you instantiate an object, the scripts on that object don’t get to run their start() function, so some of my variables and lists don’t get their initial population. I’d rather not move the scripts off the player, since other scripts rely on most of them (and their location). I think what I need to know is how to get an instantiated object to run its start() when it is instantiated (and only once, as if the item had started with the scene).
If this is not what is actually happening, and someone has ran into this issue before, please explain what is going on and if possible, a fix.
As usual, links are what I’m looking for if you have them. I don’t mind doing a little research to find my solution, however, a working solution is just as welcome as research materials.
Thanks.
EDIT:
I had a thought. Start() is just a function, a special one, but still just a function. So, maybe there is a way to call it when it object is instantiated, either from the script that does the instantiating or somehow in update based on a variable somewhere that the instantiating script changes or sets. I don’t know how to call a scripts function from a different script in a way that the script that contains the functions gets the initializations, but I’ll work on the variable solution tomorrow when I get back to working on my project. In the mean time, does anyone know of a way to call a function in the way I described?