SebLague / Solar-System

Simple solar system experiment

Home Page:https://www.youtube.com/watch?v=7axImc1sxa0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MissingReference of type CelestialBodyGenerator when changin scene

JulienCarrillo opened this issue · 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

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.

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?