SebLague / Path-Creator

Path creation asset for Unity game development
https://assetstore.unity.com/packages/tools/utilities/b-zier-path-creator-136082
MIT License
1.83k stars 319 forks source link

Constant null reference exceptions in editor #136

Open mistertoenails opened 1 year ago

mistertoenails commented 1 year ago

As soon as I add a path creator script, I get the following error over and over again until I remove the component:

NullReferenceException: Object reference not set to an instance of an object
PathCreation.BezierPath.GetPoint (System.Int32 i) (at Assets/PathCreator/Core/Runtime/Objects/BezierPath.cs:131)
CaroRed commented 1 year ago

Hello, same here I just add the script to a GameObject and appears errors on the console.

NullReferenceException: Object reference not set to an instance of an object PathCreation.BezierPath.CalculateBoundsWithTransform (UnityEngine.Transform transform) (at Assets/PathCreator/Core/Runtime/Objects/BezierPath.cs:494) PathCreationEditor.PathEditor.DrawBezierPathSceneEditor () (at Assets/PathCreator/Core/Editor/PathEditor.cs:519) PathCreationEditor.PathEditor.OnSceneGUI () (at Assets/PathCreator/Core/Editor/PathEditor.cs:337) (wrapper dynamic-method) System.Object.lambda_method(System.Runtime.CompilerServices.Closure,UnityEditor.Editor)

GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

And more, like 7 errors.

I'm using Unity 2022.1.12f1

Thanks!

ViZAlice commented 1 year ago

same. And I need to start game , then there is no more null reference. But still can't see any curve in scence , then i need to click the ResetPath. There is a curve now. But I don't think it's a permanent solution

KiritoWangCA commented 1 year ago

Yes, this problem seems to happen in unity 2022, there is no such problem in 2021.

prostolyubo commented 1 year ago

Yes, this problem seems to happen in unity 2022, there is no such problem in 2021.

I have this problem in Unity 2021.3.25f1

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <8dda741d2f7042a7a836980a676458c6>:0)
PathCreation.BezierPath.GetPoint (System.Int32 i) (at Assets/PathCreator/Core/Runtime/Objects/BezierPath.cs:131)
PathCreation.BezierPath.get_Item (System.Int32 i) (at Assets/PathCreator/Core/Runtime/Objects/BezierPath.cs:125)
PathCreation.Utility.VertexPathUtility.SplitBezierPathByAngleError (PathCreation.BezierPath bezierPath, System.Single maxAngleError, System.Single minVertexDst, System.Single accuracy) (at Assets/PathCreator/Core/Runtime/Utility/VertexPathUtility.cs:13)
PathCreation.VertexPath..ctor (PathCreation.BezierPath bezierPath, UnityEngine.Transform transform, System.Single maxAngleError, System.Single minVertexDst) (at Assets/PathCreator/Core/Runtime/Objects/VertexPath.cs:49)
PathCreation.PathCreatorData.GetVertexPath (UnityEngine.Transform transform) (at Assets/PathCreator/Core/Runtime/Objects/PathCreatorData.cs:103)
PathCreation.PathCreator.get_path () (at Assets/PathCreator/Core/Runtime/Objects/PathCreator.cs:25)
PathCreation.PathCreator.OnDrawGizmos () (at Assets/PathCreator/Core/Runtime/Objects/PathCreator.cs:82)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:189)
pazzaar commented 1 year ago

Unsure why this is specifically happening in 2022, but it looks like it's trying to initialize the _bezierPath variable in PathCreatorData.cs because its marked with the SerializeField attribute. When you add the component to your scene, _bezierPath is then set to not null and the null check in Initialize on line 46 in PathCreatorData.cs doesn't pass and the Bezier doesn't get created correctly.

Removing [SerializeField] on line 12 (the one above _bezierPath) in PathCreatorData.cs fixes this for me. Probably not the best fix in the world but its doing the trick for me at the moment.

    [System.Serializable]
    public class PathCreatorData {
        public event System.Action bezierOrVertexPathModified;
        public event System.Action bezierCreated;

        [SerializeField]  //<-- Remove this attribute
        BezierPath _bezierPath;
        VertexPath _vertexPath;

        [SerializeField]
        bool vertexPathUpToDate;
        //Rest of the code
    }

EDIT nvm https://github.com/SebLague/Path-Creator/pull/135 seems like a more reasonable solution. I would do that instead