Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException #123

Open
Fire-Cube opened this issue Aug 23, 2022 · 4 comments
Open

NullReferenceException #123

Fire-Cube opened this issue Aug 23, 2022 · 4 comments

Comments

@Fire-Cube
Copy link

When I create an empty object and add the path creator script, I get the following error messages.

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:409)
PathCreationEditor.PathEditor.DrawBezierPathSceneEditor () (at Assets/PathCreator/Core/Editor/PathEditor.cs:433)
PathCreationEditor.PathEditor.OnSceneGUI () (at Assets/PathCreator/Core/Editor/PathEditor.cs:289)
(wrapper dynamic-method) System.Object.lambda_method(System.Runtime.CompilerServices.Closure,UnityEditor.Editor)
UnityEditor.SceneView.CallOnSceneGUI () (at <7d481861b3d34328a9633ade22dcedd6>:0)
UnityEditor.SceneView.HandleSelectionAndOnSceneGUI () (at <7d481861b3d34328a9633ade22dcedd6>:0)
UnityEditor.SceneView.DoOnGUI () (at <7d481861b3d34328a9633ade22dcedd6>:0)
UnityEditor.SceneView.OnSceneGUI () (at <7d481861b3d34328a9633ade22dcedd6>:0)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <107446276b724792a53cd389e03a278b>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
NullReferenceException: Object reference not set to an instance of an object
PathCreationEditor.PathEditor.DrawBezierPathInspector () (at Assets/PathCreator/Core/Editor/PathEditor.cs:119)
PathCreationEditor.PathEditor.OnInspectorGUI () (at Assets/PathCreator/Core/Editor/PathEditor.cs:89)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass62_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <795c477f4b8b45c2b2848ba27f9a227b>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

@hendryluk
Copy link

Having the same error on Unity 2022.1.21f1 Mac Silicon.

@thangld322
Copy link

Having the same error on Unity 2022.2.1f1 Ubuntu 22.04

@pvharmo
Copy link

pvharmo commented Mar 3, 2023

I had the same issue with unity 2022.2.7f1 on Windows. The issue seems to be at line 47 of PathCreatorData.cs it checks if the bezier path is null. For some reason it seems to already be initialized but the points array in BezierPath was not initialized. To fix it I added the following lines in BezierPath.cs:

/// Is the points array null?
public bool HasPoints
{
    get
    {
        return points != null;
    }
}

and then i added the check at line 47 of PathCreatorData.cs:

- if (_bezierPath == null) {
+ if (_bezierPath == null || !_bezierPath.HasPoints) {
    CreateBezier (Vector3.zero, defaultIs2D);
}

I'm not very familiar with the codebase so i'm not sure if it will have impacts somewhere else in the code.

@jpedretti
Copy link

jpedretti commented Aug 18, 2023

If BezierPath having zero points is a valid scenario then I would change the method name from HasPoints to IsValid or IsPointsNull.
If it is not a valid scenario then I think it is worth adding an empty check after the null check.
It is an old bug. I think I'll create a pull request. @SebLague can you confirm if it makes sense for the BezierPath to have an empty points list?

edit: it looks like a problem with newer unity versions. when the editor is instantiating a new PathCreatorData it is probably setting the invalid BelzierPath instance through the [SerializeField], I removed it to test and the _bezierPath is null during PathCreatorData initialization.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants