Hi,
I have an animated character set to DontDestroyOnLoad. This character has an Animator Controller with multiple variables. When a new level is loaded, for some reason I don’t know, these variables are being reset to default values.
That would be ok, if I could just put OnLevelWasLoaded(int level) { //put all Animator Controller variables back to where they were before }, however, if I do this, variables DO NOT get affected, what I am guessing is that the OnLevelWasLoaded is being called, setting the variables to the right values, AND THEN the Animator Controller is reseting those variables after OnLevelWasLoaded was called.
So the solution I thought of and as described on Unity`s documentation, OnLevelWasLoaded can be a coroutine, so I have the following code:
private IEnumerator OnLevelWasLoaded(int level)
{
print("Level Loaded");
yield return new WaitForSeconds(0.5f);
print("Level Loaded after a half sec");
}
Problem is, the second print never happens. And if I make another method, which is a coroutine, such as:
private void OnLevelWasLoaded(int level)
{
print("Level Loaded");
StartCoroutine(DelayedOnLevelWasLoaded());
}
private IEnumerator DelayedOnLevelWasLoaded()
{
yield return new WaitForSeconds(0.5f);
print("Level Loaded after a sec");
}
The second print never gets called either! I honestly don’t know what to do… is this a known bug? Is there any other form to adjust the variables like after “start” time on a scene load?
Thanks for the help in advance,
Best regards,
Allan