So I’m working on a power line script, which so far is working well.
As you can see this is my way of doing it, but every time I move a pole I have to click ‘update lines’.
I’m still quite new to editor scripting, as I’ve just mainly never had the time to pick them up.
Is there something I’m missing to call this method when something is updated in the scene?
Thanks for anyone who can help!
Here are other possible solutions.
- Run your update lines code in update type of function (OnInspectorUpdate, Update). If you use custom editors. Forcefully calling Redraw also helps for smoother updates.
- Use OnValidate, which is executed when any inspector value has changed. Does not require custom editors.
- Use GUI.changed in custom editor to pick true state when something has changed in inspector, and run your update lines code there.
Problem solved!
I realised all I had to do was put the attribute [ExecuteInEditMode] on top of the class, and use the #if UNITY_EDITOR over the Update() loop, and cut it off afterwards.