Skip to content
New issue

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

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

Already on GitHub? # to your account

Non-private members and methods create multiple fields/buttons in derived classes' inspectors #15

Closed
PJBarczyk opened this issue Jan 24, 2024 · 0 comments

Comments

@PJBarczyk
Copy link
Contributor

When a script derives from another MonoBehaviour script, all non-private members and methods (public or protected with SerializeFieldAttribute) create extra fields or buttons.

Example

Create the following scripts in your project and add them to a GameObject:

// file: A.cs
public class A : MonoBehaviour
{
    public int aPublic;
    [SerializeField] protected int aProtected;
    [SerializeField] private int aPrivate;

    [Button] public void TestA() => Debug.Log($"Test from {nameof(A)}");
}

// file: B.cs
public class B : A
{
    public string bPublic;
    [SerializeField] protected string bProtected;
    [SerializeField] private string bPrivate;

    [Button] public void TestB() => Debug.Log($"Test from {nameof(B)}");
}

// file: C.cs
public class C : B
{
    public int cPublic;
    [SerializeField] protected int cProtected;
    [SerializeField] private int cPrivate;

    [Button] public void TestC() => Debug.Log($"Test from {nameof(C)}");
}

The inspector will look like this:

C Inspector

Related issues

The seems related to #12, though it covers an issue happening with private members too.

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

No branches or pull requests

2 participants