- Home /
Variable modified with custom editor not saved when enter play mode, even with serialized attributes.
Hello!
I read a lot of forums and questions for this problem but I'm still unable to find out the solution.
I modify a variable on a prefab from a custom editor on anothe prefab. I used all the [System.Serializable] on my custom classes but the variable is still not saved when enter in play mode.
Here my code (I simplified it to keep only the essential informations) :
Custom editor script for Arena script :
[CustomEditor(typeof(Arena))]
public class ArenaEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
Arena arena = (Arena)target;
if (GUILayout.Button("Action"))
{
foreach (Wave wave in arena.fight.waves)
{
foreach (SpawnerData spawnerData in wave.spawnersData)
{
spawnerData.ID = 1;
}
}
if (GUI.changed)
{
EditorUtility.SetDirty(target);
}
}
}
Arena script:
[System.Serializable]
public class Arena : MonoBehaviour
{
public Fight fight;
}
Fight script :
[System.Serializable]
public class SpawnerData
{
public int ID;
}
[System.Serializable]
public class Wave
{
public SpawnerData[] spawnersData;
}
[System.Serializable]
public class Fight : MonoBehaviour
{
public Wave[] waves;
}
The Arena script is on an Arena prefab instancied in the scene. This prefab references a Fight script on a Fight prefab instance in the scene too.
When I use the button on the Arena prefab instance, the ID is set to 1 on the Fight prefab. But when I enter "play" mode, the value is reset to 0.
I saw the ID value doesn't become "bold" when it changes to 1, I don't know if it means it won't be saved...
Thanks if you can bring any help to me !
Your answer
Follow this Question
Related Questions
Using a custom editor script with a prefab instance causes my variables to reset on Play 3 Answers
Serialization with custom editor, prefab not saving (again) 1 Answer
Is there a way to save a procedurally-generated mesh on the client machine? 1 Answer
Initializing a prefab from script in edit mode without breaking the connection 1 Answer