Values of object reset back to prefab values on play.

Hello,

So I am making a node network for cars to drive on. I made a script called
Node_Network, which has some custom inspector buttons which update calculate
all the speeds different nodes should have. (traffic junctions low values, then it lerps to higher the further away it goes).

Now my issue is after generating the values. It all shows nicely in the inspector of the object that I changed. It works. But when I run the scene, some values get reset to -1, which was the prefab value. And sometimes it gets set to values I had a while ago.

I have written some code to see if the values get changed in my update(). but it never triggers anything. Also generating my values, saving, and restarting unity doesn’t help either.

I checked every reference of MaxSpeed. and it’s only changed in places I want it to. I have added debug logs to see if it accidentally runs when i start the scene, and it doesnt.

So im not sure now why it keep reverting the values back to their prefab.

thanks for any help,
Aaron

It sounds like your inspector is changing values directly, and not dirtying the objects that are being edited. Be sure to use the SerializedProperty classes when editing values in custom inspectors, or make sure to dirty the objects and scene when your custom inspector makes changes.

1 Like

I see. This was the first time I made a custom editor. So perhaps that’s it. I will look into what u said. Thanks a bunch!

Cool yeah, I fixed this issue. I indeed had to dirty the object. That did the trick. Thanks a bunch.