Hello there,
I am having problems with DontDestroy on load.
SETUP:
I have a GameObject called ActiveLoading. It basically gets activated for fading scenes out and in, for loading something from database. So it handles all loading things visually.
It contains following childs:
- Textfield: LoadingText
- Image: Animation
- Background: Covers entire mobile screen Debug
- Textfield: custom debug purpose
on the parent object I have a Script attached that does following:
void Awake()
{
if (current != null && current != this)
{
Destroy(this.gameObject);
return;
}
else
{
current = this;
}
DontDestroyOnLoad(this.gameObject);
}
To have access to that UI-Screen I call DontDestroyOnLoad(this.gameObject) and save it into a static variable.
When I call somewhere else, no matter what scene I am in:
ActiveLoadingController.current.startLoading();
it will activate itself. There is also 3 public variables:
public Image CharAnimation;
public Image BackgroundImage;
public Text LoadingText;
and I define them over the editor. (Drag child elements in there)
for now it is not important what is actually going on in that startLoading function. More important is the Debug.Log();
Debug.Log("Child Elements: " + BackgroundImage + " " + CharAnimation + " " + LoadingText);
When I use the editor I get always this result and it works great:
Child Elements: ScreenBG
(UnityEngine.UI.Image) Image
(UnityEngine.UI.Image) Loading Text
(UnityEngine.UI.Text)
But on target (Android) it throws an error and does not go on (from Logfile):
(In Menu where its inited):
Child Elements: ScreenBG
(UnityEngine.UI.Image) Image
(UnityEngine.UI.Image) Loading Text
(UnityEngine.UI.Text)
Next Screen GamePlay when trying to fade out to Menu again (fadein works):
Child Elements: null null null
NullReferenceException 07-04
14:23:04.062 22730 22745 I Unity :
at
ActiveLoadingController.startLoading
(System.String startLoadingText,
Single alpha, Single fadeDuration,
Boolean showDetails) [0x0008d] in
02_MainMenu\ActiveLoadingController.cs:63
Does anyone have an idea why it does not work on target but on editor?
Thank you for your help and ideas!
all best,
Markus
I would save the cameras start position at start and use it throughout the game instead of the changing camera position
– hexagonius