SetAnimatorAtEndOfFrame - Set Twice?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
VoodooDetective
Posts: 222
Joined: Wed Jan 22, 2020 10:48 pm

SetAnimatorAtEndOfFrame - Set Twice?

Post by VoodooDetective »

I was just wondering why this code sets the animator controller/portrait active twice?

I'm tracking down an issue (probably unique to our game) where once in a long while, there will be a single frame where the NPC portrait is not set to anything and shows a big white rectangle. I thought maybe when I got rid of this, it caused the issue. Just curious if that could be.

Code: Select all

        protected virtual IEnumerator SetAnimatorAtEndOfFrame(RuntimeAnimatorController animatorController)
        {
            if (animator.runtimeAnimatorController != animatorController)
            {
                animator.runtimeAnimatorController = animatorController;
            }
            if (animatorController != null)
            {
                Tools.SetGameObjectActive(portraitImage, portraitImage.sprite != null);
            }
            yield return new WaitForEndOfFrame();
            if (animator.runtimeAnimatorController != animatorController)
            {
                animator.runtimeAnimatorController = animatorController;
            }
            if (animatorController != null)
            {
                Tools.SetGameObjectActive(portraitImage, portraitImage.sprite != null);
            }
        }
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: SetAnimatorAtEndOfFrame - Set Twice?

Post by Tony Li »

It handles some edge cases with various users' custom code. We try to set up the portrait image right away, but it's possible that the animator controller might not be assigned until the end of the frame, so we check again then. The method is virtual in case you want to change that behavior.
VoodooDetective
Posts: 222
Joined: Wed Jan 22, 2020 10:48 pm

Re: SetAnimatorAtEndOfFrame - Set Twice?

Post by VoodooDetective »

Ahhh gotcha. Thanks! I'll post here if reverting doesn't solve the issue AND I found out why.
User avatar
Tony Li
Posts: 21980
Joined: Thu Jul 18, 2013 1:27 pm

Re: SetAnimatorAtEndOfFrame - Set Twice?

Post by Tony Li »

Sounds good! I don't think reverting that will be the solution. I recommend importing the latest version (DS 2.2.25.1) into a separate project and comparing the StandardDialogueUI.cs, StandardUISubtitlePanel.cs, and StandardUISubtitleControls.cs scripts. Maybe it's something that's been fixed since the version you're using.
Post Reply