Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamically Generated Spline Problems
#1
Hello,

Having a problem and wondering if someone can help me out.

I have pieces of geometry that have a few splines in them. Right now I instantiate these pieces at the beginning of my level, and line them up, I then connect the splines using connection Curvy Connection. After this, I take my first spline and set it on the Player's SplineController in code, then call Spline.Refres(), controller.Prepare and controller.Play():

Code:
RunnerController controller = GetComponent<RunnerController>();
if (controller != null)
{
controller.Spline = manager.CurrentTile.Lanes[TileData.LaneAssignment.Center];
controller.Spline.Refresh();
controller.Prepare();
controller.Play();
}

I just cannot get the Player to follow the spline or move at all. Debugging the controller, I reach a point in Play() where IsInitialized is false because Length == 0.

If I perform these type of connection in-editor, the preview works, and I can see the connection has a proper Length.

   

At runtime, this is not the case, as the connected CP is reset back to (0, 0, 0).

   

I also tried not connecting my splines and just setting one on the player, and the same problem persists. If my move the connected CP to their original location, and then call Play() manually on the controller, it works properly. For some reason it seems the connection is resetting the CP back to origin.

Any help would be greatly appreciated!
Reply
#2
In your Start() method, wait until all relevant splines are fully initialized, see an example here. Calling Refresh() was the right idea (and it works during runtime), but it will fail at startup when child GameObjects (CP's!) arent completely processed by Unity, so you really need to yield until the spline has initialized.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Adjust radius of generated mesh via script? Shackman 1 3 03-26-2024, 01:12 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  GO can't fit end of the spline GameDeveloperek4123 3 13 03-04-2024, 11:06 AM
Last Post: _Aka_
  Keeping a fixed spline length jh092 3 16 02-21-2024, 06:25 AM
Last Post: Primrose44

Forum Jump: