Posts: 3
Threads: 1
Joined: Nov 2019
11-22-2019, 10:46 AM
(This post was last modified: 11-26-2019, 08:20 PM by _Aka_.)
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.
Posts: 2,110
Threads: 92
Joined: Jun 2017
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 3
Threads: 1
Joined: Nov 2019
(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);
Posts: 2,110
Threads: 92
Joined: Jun 2017
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 3
Threads: 1
Joined: Nov 2019
(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.
Posts: 2,110
Threads: 92
Joined: Jun 2017
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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.