Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
follow spline on instantiation
#1
Hi
What is the correct way for an instantiated prefab to follow a spline already present in scene?
So far I'm trying this in the spline controller attached to the prefab:



void Awake()
{
   var mySpline = GameObject.FindGameObjectWithTag(splinetag);
   CurvySpline mInitialSpline = mySpline.gameObject.GetComponent("CurvySpline") as CurvySpline;
   m_Spline.Refresh();
}




Any help much appreciated

Reply
#2
nvm, this seems to work:


Code:
 public CurvySpline Spline
       {
           get
           {
               var mySpline = GameObject.FindGameObjectWithTag(splinetag);
               var m_Spline = mySpline.gameObject.GetComponent("CurvySpline") as CurvySpline;


               return m_Spline;
           }
           set
           {
               if (m_Spline != value)
               {
                   if (m_Spline != null)
                       UnbindEvents();

                   m_Spline = value;
                   if (m_Spline)
                       BindEvents();
               }
           }
       }
Reply
#3
You shouldn't call Refresh() directly after getting the reference. Instead, get the reference in Awake (or Start) and yield in Start() until CurvySpline.IsInitialized==true. Calling Refresh() isn't necessary then.
Reply
#4
Thumbs Up 
(11-15-2017, 06:42 PM)Jake Wrote: You shouldn't call Refresh() directly after getting the reference. Instead, get the reference in Awake (or Start) and yield in Start() until CurvySpline.IsInitialized==true. Calling Refresh() isn't necessary then.

Great, thanks for the help.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Creating a threaded pole along a spline? spedepasanen 1 9 Yesterday, 12:25 PM
Last Post: _Aka_
  Generate Spline and Segments dynamically with a script?? mythstified 3 54 08-10-2018, 12:43 PM
Last Post: _Aka_
  Instantiating Prefab on the spline for infinite track hjk27 3 85 08-02-2018, 12:51 PM
Last Post: _Aka_
  Spline Controller Animate - Don't understand the Speed and TimeScale properties GenericJoe 12 966 07-20-2018, 09:02 PM
Last Post: GenericJoe

Forum Jump: