question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Issue] ShowIf / EnableIf does not work with Arrays or Lists in nested classes

See original GitHub issue
[ShowIf("ShowIfTest")]
public int[] test;
public bool ShowIfTest => false;

Here is the code I used to test it, no nesting. It should be hidden, but no matter what, it will always show. Tried with List as well.

I tried to search around current and past issues, but nothing came up on this issue. Is there any workaround for this issue, or did I miss the proper way to do this?

Thank you for all your work!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jurcauacommented, Mar 15, 2020

I’m not very sure either how to fix it 😦

I guess for now, if you ever find some sort of workaround, let me know!! Would be very useful to have! Thank you so much for investigating the issue however, I really appreciate it 😃

2reactions
dbrizovcommented, Mar 15, 2020

I understood why it’s now working. Look at this example.

public class _NaughtyComponent : MonoBehaviour
{
	public MyClass nest;
}

[System.Serializable]
public class MyClass
{
	[ReadOnly]
	public int[] one;

	[ReadOnly]
	public int[] two;
}

image

Even though I’ve marked the arrays with [ReadOnly] the property drawer is applied to each element of the arrays, not the arrays themselves. This is how Unity applies CustomPropertyDrawers to lists/arrays. This is what happens with the [AllowNesting] attribute. [AllowNesting] is a normal drawer, it just triggers the meta attributes’ behaviors (like [ShowIf] for instance). The problem is that NaughtyAttributes triggers the behaviors before the actual drawer is called. The drawer can’t handle the visibility itself, because the parent property is already drawn. I can make it handle the visibility itself, but the result will be just like the [ReadOnly] attribute. The array will be visible, only the child elements will not.

The reason why the [ShowIf] works for not nested arrays is that I can get the array and say to Unity - “draw the property and its children”. Before I draw the property and its children, I check if it is visible. If it’s not I don’t draw it at all.

I can’t think of a way to fix it 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

I have some trouble with nested class in Unity
Your last assignment makes no sense. First, the code is written as if Gift is a generic type, but that's not the Gift...
Read more >
Array of class with nested classes populated at awake
I have come to an issue where I have an array of a class, with a nested single class inside that which I...
Read more >
c# - When and why to use Nested Classes?
The main feature of nested classes is that they can access private members of the outer class while having the full power of...
Read more >
Unity inspector foldout attribute. You switched accounts on an
Unity inspector foldout attribute. You switched accounts on another tab or window. TabGroup is used on any property, and organizes properties into different ......
Read more >
Pybind template class. template <typename T> class py_sh
pybind11 is a lightweight header-only library that exposes C++ types in Python and vice versa, mainly to create Python bindings of existing C++...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found