- Home /
Question About EditorGUILayout.BeginFadeGroup
I notice that every time I run my game, in my custom editor that uses EditorGUILayout.BeginFadeGroup, a transition occurs. If the variables are showing before I press play, when I press play it does the transition to show them, and if they are not showing before I press play, when I press play it does the transition to hide them. I believe it has something to do with initializing the AnimBool variable. If anyone has a solution I would greatly appreciate it.
Hi @Oscar-Reyes! Can you show how you are initializing your AnimBool in your Editor's OnEnable () method?
In OnEnable() I initialized the AnimBool like this. myAnimBool = new AnimBool() I think I just figured it out thanks! I didn't realize that AnimBool has more than one constructor and one of them takes in a bool value which will set its value right away ins$$anonymous$$d waiting for it to be set in OnInspectorGUI(). I'll post an answer showing the right way later.
Answer by $$anonymous$$ · Dec 08, 2016 at 06:46 AM
Before I was initializing my AnimBool variable in OnEnable() using this constructor - myAnimBool = new AnimBool()
What I should have done is used the constructor that takes in a bool which will set the value on initialization instead of a blank AnimBool that has a value of false and a target of false. Since editor scripts also get OnEnable() called when the game starts, my AnimBool's value and target were initialized again and set to false, and when Repaint happened (which is what my AnimBool is listening for) the AnimBool would do its transition, then the AnimBool would get set again in OnInspectorGUI() which resulted in a unwanted transition. So, the way to go about it is to use...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.AnimatedValues;
[CustomEditor(typeof(MyClass))]
public class MyClassEditor : Editor
{
bool showSettings;
AnimBool myAnimBool;
void OnEnable()
{
myAnimBool = new AnimBool(showSettings);
}
public override void OnInspectorGUI ()
{
//Code to show, hide variables and draw inspector
}
}