Hello everyone,
I have a custom created menu for a dialogue with a specific character in the game. It consists on a canvas with two children images, each one with an Animator. It's basically two big pictures of the player and this character, each on one side, and they animate whenever they talk (like a big portrait of each, but I want it to appear only with this character).
The menu is a Unity UI Prefab, "Start the game locked off?" is deactivated, "Appear type" is Manual, and "Enabled on start?" is deactivated too. Positioning is also manual. Is doesn't really have any menu elements, only the two portraits with their respective animators.
Now, I have a script attached to each one of the images which goes like this:
-----------
public class ConversationUIController : MonoBehaviour {
private Animator characterAnimator;
private Animator uiAnimator;
public string characterName;
public string[] animationParameters;
// Use this for initialization
void Start () {
characterAnimator = GameObject.Find(characterName).GetComponent<Animator>();
uiAnimator = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
foreach (string parameter in animationParameters) {
uiAnimator.SetBool(parameter, characterAnimator.GetBool(parameter));
}
}
}
-----------
So it basically syncs the real characters' Animators with the Menu Animators: whenever the character is talking, the portrait will talk too.
The issue is that the first time the scene is loaded, everything works fine, but when I go to a different scene and back again, the "uiAnimator" object has been destroyed, and I get a MissingReferenceException. The portraits appear, but they don't animate.
How can I prevent this from happening? I tried with "DontDestroyOnLoad" with no success.
Adventure Creator: v1.62.2
Unity: 2017.4.2f2
Thank you
Comments
That seems to have made it! Thanks @ChrisIceBox !