Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spline Controller and Editor Scripts: changes not saved
Hello there!

Background: I have several cars in scene with SplineController on them an dI want to distribute them along path with code. To do so I just need to foreach them  and change their Initial Positions.

I'm trying to change Spline Controller properties in Editor by code.
For example:
float foo = 0.1f*bar;
splineController.InitialPosition = foo;
(It is executed by my button pressed in Editor Mode)
And I see the desired result.

But once I switch Unity to Play Mode, my changes are gone!


If, after pressing my button but before going to Play Mode, I select my GameObject with SplineController and change something in the Inspector manually (doesn't matter what exactly, for example, switch off and then back on Play Automatically checkbox), the changes get saved.


Obviously, Inspector does something after changes are done inside it, what my script does not.
But I wasn't able to figure out what exactly.
What should I do in code, in Editor Mode, to make my changes be saved without manually touching the Inspector?

Thank anyone for relative answer!
Hm, that's strange. If you touch the inspector, OnValidate() is called, that's the only difference in my code. Also, the inspector marks the object dirty, so Unity serialization knows about it. But as setting InitialPosition() touches a field flagged as serialized, Unity should handle that as well when called from code.

If you run your script, does Unity sets the scene dirty (* after the scene name in the titlebar)? If not, that's the cause of the issue. Btw, what Unity version you're using?

Possibly Related Threads…
Thread Author Replies Views Last Post
  Object enter spline from collider. camelart27 13 74 12-02-2020, 06:22 PM
Last Post: Zhavier
  Kinematic object on spline Dayus 3 69 11-23-2020, 07:38 PM
Last Post: _Aka_
  Getting MissingReferenceException from the component pool when I destroy a spline Excrubulent 5 133 11-22-2020, 11:38 AM
Last Post: _Aka_
  Generate Mesh Spline from GameObject processor 4 311 10-01-2020, 11:00 AM
Last Post: _Aka_

Forum Jump: