Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creting SplineControllers thru code generating errors
#1
Hey,

I'm creating lots of vehicle objects with SplineControllers assigned to each. Below code is how I'm creating them. Objects are being created and scene is running fine but there are lots of errors in the console. I wonder if this is how they should be created. I'm precreating them inside Awake then activating on SpawnStart which is where exceptions are triggering (block.SetActive(true)).

I updated the version to 7 but still getting those errors. 

Code:
       
void SpawnInit()
       {
           offsets = new Offsets[] {
               new Offsets() { angle = 84.0f, radius = 5.0f },
               new Offsets() { angle = 0.0f, radius = 0.0f },
               new Offsets() { angle = -84.0f, radius = 5.0f }
           };

           allBlocks = new List<GameObject>();

           //spline.Refresh();
           float splineLength = 1f;

           newDistance = initSpacing;
           while (newDistance < splineLength)
           {
               GameObject block = new GameObject();
               block.SetActive(false);
               blockSplineController = block.AddComponent<SplineController>();
               blockSplineController.Spline = spline;
               blockSplineController.UseCache = true;
               blockSplineController.Speed = carSpeed;
               blockSplineController.PlayAutomatically = false;
               blockSplineController.RelativePosition = newDistance;

               offsetData = offsets[Random.Range(0, 3)];
               blockSplineController.OffsetAngle = offsetData.angle;
               blockSplineController.OffsetRadius = offsetData.radius;
               blockSplineController.OffsetCompensation = true;

               GameObject prefab = Instantiate(ObstacleBlocks[Random.Range(0, ObstacleBlocks.Length)]);
               prefab.transform.parent = block.transform;

               allBlocks.Add(block);
               
               newDistance += spacing;
           }
       }

void SpawnStart()
{
foreach (GameObject block in allBlocks)
{
               block.SetActive(true);
               blockSplineController = block.MMGetComponentNoAlloc<SplineController>();
               blockSplineController.Play();
}
}

NullReferenceException: Object reference not set to an instance of an object
FluffyUnderware.Curvy.Controllers.CurvyController.Initialize () (at Assets/Plugins/Curvy/Controllers/CurvyController.cs:826)
FluffyUnderware.Curvy.Controllers.CurvyController.OnEnable () (at Assets/Plugins/Curvy/Controllers/CurvyController.cs:572)
UnityEngine.GameObject:SetActive(Boolean)
FluffyUnderware.Curvy.Examples.SpawnObstacles:SpawnStart() (at Assets/Scripts/SpawnObstacles.cs:92)
FluffyUnderware.Curvy.Examples.SpawnObstacles:OnMMEvent(TopDownEngineEvent) (at Assets/Scripts/SpawnObstacles.cs:118)
MoreMountains.Tools.MMEventManager:TriggerEvent(TopDownEngineEvent) (at Assets/TopDownEngine/ThirdParty/MoreMountains/MMTools/Events/MMEventManager.cs:162)
MoreMountains.TopDownEngine.TopDownEngineEvent:Trigger(TopDownEngineEventTypes, Character) (at Assets/TopDownEngine/Common/Scripts/Managers/GameManager.cs:59)
MoreMountains.TopDownEngine.ActionButton:StartAction() (at Assets/Scripts/ActionButton.cs:23)
UnityEngine.EventSystems.EventSystem:Update() (at /Applications/Unity/Hub/Editor/2019.3.14f1/Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)


NullReferenceException: Object reference not set to an instance of an object
FluffyUnderware.Curvy.Controllers.SplineController.InvokeEventHandler (FluffyUnderware.Curvy.Controllers.CurvySplineMoveEvent event, FluffyUnderware.Curvy.Controllers.CurvySplineMoveEventArgs eventArgument, FluffyUnderware.Curvy.CurvyPositionMode positionMode, FluffyUnderware.Curvy.CurvySplineSegment& postEventsControlPoint, System.Boolean& postEventsIsControllerOnControlPoint, System.Single& postEventsControlPointPosition) (at Assets/Plugins/Curvy/Controllers/SplineController.cs:927)
FluffyUnderware.Curvy.Controllers.SplineController.HandleReachingNewControlPoint (FluffyUnderware.Curvy.CurvySplineSegment controlPoint, System.Single controlPointPosition, FluffyUnderware.Curvy.CurvyPositionMode positionMode, System.Single currentDelta, System.Boolean& cancelMovement, FluffyUnderware.Curvy.CurvySplineSegment& postEventsControlPoint, System.Boolean& postEventsIsControllerOnControlPoint, System.Single& postEventsControlPointPosition) (at Assets/Plugins/Curvy/Controllers/SplineController.cs:909)
FluffyUnderware.Curvy.Controllers.SplineController.EventAwareMove (System.Single distance) (at Assets/Plugins/Curvy/Controllers/SplineController.cs:779)
FluffyUnderware.Curvy.Controllers.SplineController.Advance (System.Single speed, System.Single deltaTime) (at Assets/Plugins/Curvy/Controllers/SplineController.cs:487)
FluffyUnderware.Curvy.Controllers.CurvyController.InitializedApplyDeltaTime (System.Single deltaTime) (at Assets/Plugins/Curvy/Controllers/CurvyController.cs:675)
FluffyUnderware.Curvy.Controllers.SplineController.InitializedApplyDeltaTime (System.Single deltaTime) (at Assets/Plugins/Curvy/Controllers/SplineController.cs:531)
FluffyUnderware.Curvy.Controllers.CurvyController.ApplyDeltaTime (System.Single deltaTime) (at Assets/Plugins/Curvy/Controllers/CurvyController.cs:1024)
FluffyUnderware.Curvy.Controllers.CurvyController.Update () (at Assets/Plugins/Curvy/Controllers/CurvyController.cs:605)
Reply


Messages In This Thread
Creting SplineControllers thru code generating errors - by curvyuser007 - 05-26-2020, 09:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Errors in Built Application in CurvySplineSegment TdayMFG 7 3,287 04-13-2025, 09:24 AM
Last Post: _Aka_
  Updated package in 2022 LTS resulted in multiple errors scr33ner 2 1,688 01-13-2025, 09:32 AM
Last Post: _Aka_
  Small errors in end tangents, by davelloyd _Aka_ 0 939 01-07-2025, 11:14 AM
Last Post: _Aka_
  Playmaker setup errors and missing scripts? justifun 9 6,368 08-06-2024, 09:41 AM
Last Post: _Aka_

Forum Jump: