- Home /
Changes in the Custom Editor are not applied when restarting Unity
Hi, I created a Custom Editor in Unity and changing the variable in it, I change the inscription on the button.
Unfortunately, when I restart Unity, I have to press the object for changes to occur. Otherwise they are all the same settings.
How to make them change when Unity starts changing immediately? The first picture - As it should be Second picture - After a scene is loaded or Unity restarted.
Code1:
[CustomEditor(typeof(UiButtonLevelScript))]
public class UiButtonLevelInspector : Editor
{
bool showObjectList = false;
public override void OnInspectorGUI()
{
UiButtonLevelScript uiButtonScript = (UiButtonLevelScript)target;
showObjectList = EditorGUILayout.BeginFoldoutHeaderGroup(showObjectList, "Obiekty");
if (showObjectList)
{
GUILayout.Label("Główny przycisk.");
uiButtonScript.ButtonLevel = (Button)EditorGUILayout.ObjectField(uiButtonScript.ButtonLevel, typeof(Button), true);
GUILayout.Label("Pole tekstowe przycisku.");
uiButtonScript.TextButton = (Text)EditorGUILayout.ObjectField(uiButtonScript.TextButton, typeof(Text), true);
}
EditorGUILayout.EndFoldoutHeaderGroup();
GUILayout.Label("Poziom do obsługi przez przycisk");
GUILayout.Label("Lista poziomów zapisana w GlobalVariable");
uiButtonScript.LvlSelect = (GlobalVariable.LvlList)
EditorGUILayout.EnumPopup("Level: ", uiButtonScript.LvlSelect);
if (GUI.changed)
{
EditorUtility.SetDirty(uiButtonScript);
EditorSceneManager.MarkSceneDirty(uiButtonScript.gameObject.scene);
if (uiButtonScript.ButtonLevel && uiButtonScript.TextButton)
{
uiButtonScript.LvlVariableData = GlobalVariable.lvlVariablesData[(int)uiButtonScript.LvlSelect];
uiButtonScript.TextButton.text = uiButtonScript.LvlVariableData.GetTextButton();
if (uiButtonScript.LvlVariableData.GetFontSize() != 0)
uiButtonScript.TextButton.fontSize = uiButtonScript.LvlVariableData.GetFontSize();
uiButtonScript.ButtonLevel.name = "UiButtonLevel " + uiButtonScript.LvlVariableData.GetTextButton();
}
}
}
private void OnEnable()
{
UiButtonLevelScript uiButtonScript = (UiButtonLevelScript)target;
EditorUtility.SetDirty(uiButtonScript);
if (uiButtonScript.ButtonLevel && uiButtonScript.TextButton)
{
uiButtonScript.LvlVariableData = GlobalVariable.lvlVariablesData[(int)uiButtonScript.LvlSelect];
uiButtonScript.TextButton.text = uiButtonScript.LvlVariableData.GetTextButton();
if (uiButtonScript.LvlVariableData.GetFontSize() != 0)
uiButtonScript.TextButton.fontSize = uiButtonScript.LvlVariableData.GetFontSize();
uiButtonScript.ButtonLevel.name = "UiButtonLevel " + uiButtonScript.LvlVariableData.GetTextButton();
}
}
}
Code2:
public class UiButtonLevelScript : MonoBehaviour
{
#region Variable
[Header("Przycisk")]
public Button ButtonLevel;
[Header("Pole tekstowe.")]
public Text TextButton;
[Header("Dane do danego poziomu.")]
public LvlVariable LvlVariableData;
[Header("Wybrany poziom do obsługi.")]
public GlobalVariable.LvlList LvlSelect;
#endregion
}
Code1:
Answer by tdx110 · Feb 07, 2021 at 12:17 AM
I know that this is due to the fact that I have a custom editor connected to Prefabs. I don't know how to solve it. And I found a new problem. I don't know how, but buttons 2 and 7 remain as they should be. When I turn on the button inspector, it changes as it should be.
Your answer
Follow this Question
Related Questions
Cannot get a class to show up correctly in a custom inspector 0 Answers
Why is my propertydrawer being automatically disabled? 1 Answer
C# unity custom editor multiple different components but same base class 2 Answers
I have some question about custom Hierarchy 0 Answers
Make a custom inspector that shows a group of variables in form of list 2 Answers