Skip to content

[Bug Report] Conditional attributes cannot find private fields of base classes #125

@snarlynarwhal

Description

@snarlynarwhal

The conditional attributes like ShowIf / HideIf do not work when the sourceHandle parameter is a private field of a serializable classes that is a base class of the serialized object. Changing the sourceHandle access modifier from private to public fixes the problem.

For example, this does not work:

[Serializable]
public class BaseClass 
{
    [SerializeField] private bool visible;
    [SerializeField, ShowIf(nameof(visible), true)] private int property;
}

[Serializable]
public class ChildClass : BaseClass
{
    // More fields...
}

It shows the following error (edited for clarity):

[Editor Toolbox] ShowIfAttribute: (property) property in (object): Member (visible) not found.

It only works after changing the field access modifier from private to protected:

[SerializeField] protected bool visible;

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions