Open Kronoxis opened 3 months ago
this works pretty well! However, if I move a Spline Node and then Ctrl Z, the object controller doesn't update properly & the relevant gameobjects aren't Removed properly, because of this nullref. then I have to delete all the child gameobjects and refresh the spline
In other situations, the followers will get de-synced for some other reason I haven't totally narrowed down, and updating the spawn distance will create a new line of followers without removing the old ones, WITHOUT throwing the nullref.
also, I seem to occasionally get <10 fps in scene view (not even play mode) with an object controller Selected in hierarchy, even if only ~a dozen empty child objects exist. Updating the spawn distance value (*or other values) sometimes causes it, while deselecting and reselecting the object can improve it. This isn't a huge deal, but the same setup never had this issue before testing this.
hmmm, also after leaving play mode it will rebuild the followers without deleting the ones already there, leading to many extra copies
As requested on Discord, adds a feature to the ObjectController component that allows the controller to automatically spawn objects with a fixed distance gap.
Implementation
Adds a third
Spawn Method
calledDistance
, which when selected exposes aSpawn Distance
float field. The distance field has a minimum value of 0.001f to avoid spawning infinite objects. This is implemented using theCalculateLength
method, which is cached until the spline is rebuilt or the clip range changes.Notes
The very last object will be glued to the end of the spline (accounting for clipTo), which sets the distance between the n-1-th and n-th object somewhere between 0 and
Spawn Distance
. If this is undesired, one can change theCeilToInt
inGetTargetCount()
toFloorToInt
to simply not spawn the last object until there is enough room for one. We could of course add another variable to control this behaviour, if desired.Tests
The test branch can still be used for some basic tests. Set the
SpawnMethod
toDistance
and play around with the spline, clip range andSpawnDistance
values.This PR should not introduce any breaking changes, as the default behaviour of the ObjectController remains unchanged. It simply exposes an optional setting for convenience.