Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Assigning "OnControlPointReached" and "OnEndReached" values during runtime?
Hi there, 

I'm instantiating a spawned object during runtime, then adding a Spline Controller script to it and assigning its Spline via code.  This part is all working great.  However, under the Events area of the Spline Controller script (viewed in the Inspector), I need to then assign new values for "On Control Point Reached" and "On End Reached", both the listener itself and the Event Handler designation.  This where I get stuck.

I know I'm close... it should be something like this:

public int numberOfVehiclesinFleet = 4;
public List<GameObject> newVehicleFleet = new List<GameObject>;

void Start(){

void CreateNewVehicles(){

     for (int i = 0; i < numberOfVehiclesInFleet, i++){
          GameObject newVehicle = Instantiate (Resources.Load("Vehicle", typeof(GameObject)) as GameObject);
          newVehicleFleet.Add (newVehicle);

     for (int i = 0; i < numberOfVehiclesInFleet; i++){
          newVehicleFleet[i].GetComponent<SplineController>().enabled = true;

The question marks are where I get stuck.  How do I add and assign a new "OnControlPointReached" and "OnEndReached" here?

I've also attached a photo of what I WANT it to look like.  In the meantime, I've created a workaround where I assign these values to the actual Resource so they are already assigned when they are Instantiated.  But this is what I'm trying to achieve (attached).

Any advice?  I'm stuck!

Thank you!

Attached Files Image(s)

Those events are of type CurvySplineMoveEvent, which inherits from UnityEvent, a events class provided by Unity. So you can treat them as any other Unity event, or use the functionalities provided by CurvySplineMoveEvent, like AddListenerOnce(...) that make sure that you don't have the same listner attached multiple times.

You have an example usage in one of the example scenes, TrainCarManager, in the setController method
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Making long roadmesh runtime migeg 8 152 08-03-2020, 02:47 PM
Last Post: _Aka_
  Letting users create and edit splines at runtime skote 1 124 07-12-2020, 04:49 PM
Last Post: _Aka_
  Null reference when spline controller added runtime jh092 1 191 06-19-2020, 09:21 AM
Last Post: _Aka_
  instantiate Spline Controller at runtime PretzelStudios 2 416 05-07-2020, 09:03 PM
Last Post: PretzelStudios

Forum Jump: