Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
instantiate Spline Controller at runtime
#1
Hi all,

Please could someone point me in the right direction?

I have a script that instantiates a gameobject with a spline controller attached.
Is there a way of telling this gameobject what spline to use? Iv searched the documentation but cant seem to find an answer.

At the moment it spawns in but cannot associate itself to my spline.

Thanks in advance.
Reply
#2
Hi,
Is this what you are looking for?
https://forum.curvyeditor.com/thread-839.html
Available for freelance work, feel free to reach out: toolbuddy.net
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Reply
#3
Ok Cross-checking that thread I did manage to figure this out.


For anyone in the future here is my code to make this work.

Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FluffyUnderware.Curvy.Controllers;
using FluffyUnderware.Curvy;

public class VehicleSpawner : MonoBehaviour
{
   private SplineController sc;
   public GameObject[] vehicles;
   public float spawnInterval;
   public CurvySpline road;

   private void Start()
   {
       
       StartCoroutine(SpawnVehicles());
   }

   private IEnumerator SpawnVehicles()
   {
       while (true)
       {
           int index;
           index = Random.Range(0, vehicles.Length - 1);
           Instantiate(vehicles[index]);
           sc = vehicles[index].GetComponent<SplineController>();
           sc.Spline = road;
           yield return new WaitForSeconds(spawnInterval);
       }
   }
}

Hope it helps Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Filling a closed spline dynamically rickgplus 1 231 04-16-2025, 08:56 AM
Last Post: _Aka_
  Disable a spline's gizmo when not selected or disabled. mikechr2000 1 286 02-03-2025, 09:34 AM
Last Post: _Aka_
Information Questions regarding spline colliders and collisions with rigidbodies Spyboticer 7 1,102 01-20-2025, 12:25 PM
Last Post: _Aka_
  Extrude mesh along spline. New and confused user GhostStalker 3 531 01-02-2025, 09:58 AM
Last Post: _Aka_

Forum Jump: