public variables assigned by script in editor vanish at runtime - but manually entered values persist

I’m using an editor script to assign values to public variables on a game object.
When I press “Play”, those values vanish, in game - - they’re also gone when the game stops running and I’m back in editor mode.

If I enter those exact same values by hand rather than script, then they persist when the game runs.

How can I get unity to save those values assigned by script?

Use the editorutility.setdirty. This will mark the values as changed. Then when you run they will not get reverted.

I just noticed the say not to use this in scenes anymore.
But the page shows the updated way.

You can still use this though. And is the way you do it for prefabs.

If you look at the two custom editor scripts here, you should be able to see what the difference is. If you’ve written your logic differently, you should consider using one of the described techniques: