05-26-2020, 09:09 PM
(This post was last modified: 05-26-2020, 09:11 PM by curvyuser007.)
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.
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)
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)