Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SplineController Delta after instantiate(Bug?)
#1
Hi,

I have a Spline setup in my scene and i want to create objects at runtime that follow the spline. I'm using objects with a spline controller. these are then setup as prefabs. when i instantiate them i want to then apply an offset so they are staggered along the spline so after instantiate i want to call ApplyDeltaTime() on the controller with random values.

Problem is when calling ApplyDeltaTime() with a random value on the newly instantiated spline controller the position remains 0 on the spline so all objects are at the same position along the spline.

I suspect this is a bug and something hasn't initialised on the spline controller. or reinitialise after setting position.

Question is, is there a way around this? 

In the sample project i have  a sline and two controllers in scene and a prefab in assets with a controller. One controller in the scene is left at delta 0 which starts at the beginning and one delta 5. in the script the delta 5 is reference by the script and apply delta called passing in 5. this works and moves the object to delta 5, then the prefab is instantiated calling delta with 2 so this should result in three cubes moving along the spline staggered along the spline but the instantiated object remains at delta 0 start position.
Reply
#2
Hi
From reading your message, I don't see anything wrong in your steps, so I will need to test your project to find ou what is wrong. I will do that on Monday or Tuesday. I will keep you updated.
The issue appears only for one frame or does it stay for all the duration?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
(11-22-2019, 03:13 PM)_Aka_ Wrote: Hi
From reading your message, I don't see anything wrong in your steps, so I will need to test your project to find ou what is wrong. I will do that on Monday or Tuesday. I will keep you updated.
The issue appears only for one frame or does it stay for all the duration?

For the duration. So the following code I call ApplyDeltaTime(2); in the Start() function after instantiation but it starts at position 0, where i would have expected it to be progressed by 2 seconds into the path. Note that it works as expected if I then call ApplyDeltaTime(2); in the update function upon pressing a key, you can see the object progressed each time pressing the key(though i didn't add that code in the sample).

Code:
SplineController controllerPrefabInstance = GameObject.Instantiate<SplineController>(controllerPrefab);


controllerPrefabInstance.name = "ControllerDelta2";
controllerPrefabInstance.Spline = mainspline;
controllerPrefabInstance.ApplyDeltaTime(2);
Reply
#4
There are some things in you explanation that I am not sure to understand properly, so I will in the following give a lot of information, some of it might not be usefull for you, but I think that the solution to your problem lies there:
  • ApplyDeltaTime is called automatically by Curvy at each unity update, and is called with the duration since last update as a parameter, so yoy don't need to call it manually to make things work
  • For that method to make the object move, the speed field should be different than zero
  • I think the easiest way to do what you want is to simply use the Position property. This way you spawn an object, set where it should be to achieve the staggering, and then let it be
Did this help?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
(11-22-2019, 04:44 PM)_Aka_ Wrote: There are some things in you explanation that I am not sure to understand properly, so I will in the following give a lot of information, some of it might not be usefull for you, but I think that the solution to your problem lies there:
  • ApplyDeltaTime is called automatically by Curvy at each unity update, and is called with the duration since last update as a parameter, so yoy don't need to call it manually to make things work
  • For that method to make the object move, the speed field should be different than zero
  • I think the easiest way to do what you want is to simply use the Position property. This way you spawn an object, set where it should be to achieve the staggering, and then let it be
Did this help?

I understand you don't need to call it, it was just initially after instantiation and i added a test with the space bar to see if it worked, it works when calling later after instantiation but not directly after instantiation.
Speed is set to 10 in the prefab and it move along the spline as expected by the controller.

Setting the position does work, i'll use that instead but it does seem like a bug if you get a chance to look at it.
Reply
#6
Hi,

I did some tests and here is what I found:
When instantiating an object using GameObject.Instantiate, its Start() method does not get called directly after the Instantiate call. So when you call controllerPrefabInstance.ApplyDeltaTime(2), it is done before the call to Start(). And it is in the Start method that the controller checks the value of PlayAutomatically to make the controller play. So if you want the code you posted to work, you need to manually call Play before calling ApplyDeltaTime.

Also, a reminder to you and other forum users: do not include Curvy Splines in the projects you share. This is a violation of the Asset Store Terms and Service. The only way to get Curvy Splines should be by buying it.

Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Move SplineController in rhythm of song electricpunch 10 1,948 05-16-2019, 09:02 PM
Last Post: _Aka_
  Script inheriting SplineController doesn't work the same as adding component? clearleaf 1 533 04-28-2019, 12:41 PM
Last Post: _Aka_
  Working with, around, or against SplineController Livealot 2 1,296 07-20-2018, 06:45 PM
Last Post: Livealot
  how do I position a splineController on a spline in runtime to an exact position? hawken 8 7,174 01-19-2018, 12:01 PM
Last Post: _Aka_

Forum Jump: