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

Fields hiding the inherited members of Component are displayed multiple times #12

Closed
PJBarczyk opened this issue Dec 26, 2023 · 3 comments

Comments

@PJBarczyk
Copy link
Contributor

Summary

Serialization of fields that hide the inherited members of Component (e.g. rigidbody, camera, collider) causes the fields to be displayed five times in the inspector.

  • It does not matter whether the field is serialized by having SerializeFieldAttribute or public access modifier.
  • Out of the five fields, the appropriate field is displayed as the second one.
  • When multiple issue-causing fields are present, the fields are grouped with each other, creating five groups of fields. Fields that behave correctly are displayed in the second group.
  • Type of the field does not matter; it can be the same, derive other UnityEngine.Object or be a primitive type.
  • The duplicated fields have the same property path, and so they are synchronized when the value is changed.
  • The issue does not occur when serializing auto-properties using the SerializeFieldAttribute for the backing field - the field is displayed only once.

Reproduction

In a newly created project, add the Alchemy 1.0.3 package. Then, create a new script with the following contents:

public class ExampleBehaviour : MonoBehaviour
{
    [SerializeField] private new Rigidbody rigidbody;
    [field: SerializeField] public Transform camera { get; private set; }
    public float light;
}

After adding this script to a game object, the inspector will look like this:

Inspector window

Note that the icons of the extraneous fields lack the icon and concrete component name. After changing the selection and reselecting the behaviour again, the icons and appropriate names appear.

Environment

The issue was found and reproduced in the following environment:

  • Unity 2023.1.16f1 and 2023.2.3f1
  • Alchemy 1.0.3
@AnnulusGames
Copy link
Owner

Fixed in #25. This was due to a non-SerializedField property being included in the member enumeration.

@Akeit0
Copy link
Contributor

Akeit0 commented Feb 17, 2024

#25 doesn't work with this case.

[Serializable]
public class MyBaseClass
{
    public int value { get; set; }
}

[Serializable]
public class MyClass : MyBaseClass
{
    [SerializeField]  int value;
}

[SerializeField] MyClass myClass;

@AnnulusGames AnnulusGames reopened this Feb 17, 2024
@AnnulusGames
Copy link
Owner

I have added a fix for this in #28. This will cause properties that do not have a SerializedField to be completely ignored.

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

3 participants