Solar-System icon indicating copy to clipboard operation
Solar-System copied to clipboard

MissingReference of type CelestialBodyGenerator when changin scene

Open JulienCarrillo opened this issue 3 years ago • 2 comments

Hello everyone, I've been struggling for few days with a null ref when I want to reload or change scene. image image image I feel like the script keeps running when I change scenes. I tried to destroy and re instantiate or disable and enable my script for my planet and my camera but still the same error.

The error seems to come from the PlanetEffects.cs because when I remove it, the error disappears but I have no more ocean or atmosphere. I also noticed that in runtime, when I refresh PlanetsEffect (line break and save) the error disappears and everything works again. I'm pretty new to gamedev and I'm sure I'm missing a concept or something. If anyone can enlighten me that would be great! I hope I was clear in my explanation.

in advance, thank you

JulienCarrillo avatar Aug 04 '22 09:08 JulienCarrillo

I think you figured out most of it. PlanetEffects.cs, unlike many other scripts, is a scriptable object, which means its instance is always saved. (when in edit mode, it's also saved on the disk) Workaround? Probably would involve making pivate effectHolders list public, clearing it and calling the Init() method when done changing the scene.

Though this is my speculation and I couldn't test it, I believe that's what's going on.

Delofon avatar Aug 04 '22 12:08 Delofon

Thanks for your reply : I tried something like this in my loading system image I also made my effectHolders list public. I did the same for the Init method to be able to call them in my loading system, but still the same error. Did I do something wrong?

JulienCarrillo avatar Aug 04 '22 13:08 JulienCarrillo