[Custom Inspector] Property resets after starting playmode

Hey guys, I try to use a custom inspector for my laser handler, but every time I set the property "EmissionColor" to something and start the playmode it resets. I know I have to serialize it, but I don't know how to do it in this case, can you please help me?

Here is my Code: using UnityEngine; using System.Collections; using UnityEditor;

1 Reply

The problem here is that you are not dirtying the serialized data on the target LaserHandler object. There are a number of ways to approach this, but in general the best option for setting properties inside of OnInspectorGUI is to use SerializedProperty instead of directly accessing fields on the target object. Doing so will properly serialize data, handle undo/redo, multi selection, etc. The pattern is something like this: