Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Spline field in a nested class throws exception in inspector.

Discussion in '2022.1 Beta' started by MechaWolf99, Mar 11, 2022.

  1. MechaWolf99


    Aug 22, 2017
    If you have a Spline field in a class that is a field of a MonoBehaviour, the inspector will throw exceptions when trying to view the contents of the Spline field.

    Code (CSharp):
    1. public class SplineExample : MonoBehaviour
    2. {
    3.     [SerializeField] private SplineHolder _splineHolder;
    4. }
    6. [System.Serializable]
    7. public class SplineHolder
    8. {
    9.     [SerializeField] private Spline _spline;
    10. }
    The reason for this is because you are using a naïve implementation to get the Spline value from a SerializedProperty and directly using the property path to get the field info and passing the SerializedObject's target as the object for the GetField(..).

    What you need to do is split up the path and walk over the whole thing getting each field along the way and using the value from the previous field to get the value of the next. I have a implementation myself that supports both arrays/lists and SerializeReference if you want to take a look at it.
    Github Repo (MIT)

    Case 1410152
    Last edited: Mar 14, 2022
  2. Baste


    Jan 24, 2013