Page 1 of 1

SetAnimatorAtEndOfFrame - Set Twice?

Posted: Tue Feb 22, 2022 5:40 pm
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);
            }
        }

Re: SetAnimatorAtEndOfFrame - Set Twice?

Posted: Tue Feb 22, 2022 5:58 pm
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.

Re: SetAnimatorAtEndOfFrame - Set Twice?

Posted: Tue Feb 22, 2022 6:24 pm
by VoodooDetective
Ahhh gotcha. Thanks! I'll post here if reverting doesn't solve the issue AND I found out why.

Re: SetAnimatorAtEndOfFrame - Set Twice?

Posted: Tue Feb 22, 2022 6:45 pm
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.