(Splines package) How do I detect spline changes made in the inspector?

I’m currently experimenting with the new spline package (Splines | Splines | 1.0.0-pre.7 (unity3d.com)) and I want to detect its changes to be able to regenerate a mesh based on the spline data. There is a Spline.changed Unity Event when the spline is changed in the world (adding new points, moving points etc) but it is not called for changes made in the inspector. So what is the preferred way of detecting this? I need to detect changing the spline points in the inspector as well as enabling/disabling the closed property. Maybe it’s possible to display the SplineContainer properties in the custom editor for my own script so that I can detect it with EditorGui.BeginChangeCheck, but that feels super hacky. Any ideas?

This should be working already. If you look at the Loft Road sample you can see that modifying the SplineContainer is updating the road mesh.

Where are you subscribing to Spline.changed?

Also, if in the editor it’s a good idea to use the EditorSplineUtility.afterSplineWasModified instead. This event will only fire once per-frame, which is helpful in cases where the callback is potentially expensive.

Nope the road mesh in the Loft Road example is not updating:
j6a31x
This is with Unity 2022.1.0b2.2474 with Spline package pre 7 (but have also tested with pre 5)

Ok, it seems this was a bug that was fixed recently. It will be addressed in pre.8.

1 Like

Ok, thanks for the update.

@kaarrrllll EditorSplineUtility.afterSplineWasModified works fine when the script is on the same game object as the spline container, but doesn’t work when the script is on a child GO. How do I point to the spline I want to register the event for? In this example both generators are referencing the parent spline GO.

9561541--1352035--upload_2024-1-4_13-23-8.png

I’m guessing that the code you’re referencing is in an Editor class, which if the parent is selected won’t be executed. You need to make sure that the code responsible for updating the mesh is running.

Ahh I get you, that makes sense, thanks!

@kaarrrllll is there an event for entering / exiting the spline edit mode? E.g. for calling expensive operations only once all spline changed have been made?