I’m trying to figure out the “right” way to manage the visibility of actors that are organized into a hierarchy. For a simplified example, assume I have an Actor class that contains a root scene component that in turn has a static mesh and a Child Actor component as children, and that child actor contains a root scene component that in turn contains a static mesh and a Text Render component (that acts as some sort of label) as its children.
In the child, the visibility of the label is conditioned upon some logic that is internal to the child - sometimes it is visible and other times not. In the parent, the visibility of the whole child actor is also conditioned upon some logic that is internal to the parent.
When the parent hides the child, it uses the SetVisibility method on the Child Actor (specifically, on its root scene component). The problem is that the visibility of a parent does not seem to determine the visibility of its children - I guess my expectation was that if I hide a component, its children and their children would all be hidden.
The “Propagate to Children” flag on SetVisibility doesn’t quite do what I need - it seems to effectively iterate over all the children and call SetVisibility on them and their descendants. The problem is that this overrides the visibility state of the children - when I go to make the child visible again, the label is visible now even if it shouldn’t be.
My workaround is to manually manage the state of everything - each actor class has its own SetVisible method that in turn calls SetVisible on its respective children, based on checking the logic for what should be visible or not at the time of the call, or in some cases by storing it in another visibility variable in that child. This works but is a lot of work and is also redundant because the correct state was already present in the bVisible flag, but it gets stomped any time some ancestor’s visibility is changed.
This is an “am I doing this right?” question. As in, I have things working, but it sure seems like I’m doing a lot of extra work so it has me wondering if I’ve headed down the wrong path. I can understand that there could be scenarios in which changing the visibility of a parent should not effect the visibility of the children, but it sure seems like an exception rather than the rule, but the current behavior seems (unless I’m doing it wrong) to support that corner case functionality instead of what seems like the more usual case.
An analogy would be to look at just about any GUI toolkit out there: each individual widget can have its own visibility state that represents its own notion of whether or not it and its children should be visible right now. But the /actual/ visibility is determined not just by that, but also the current visibility of its ancestors. Within a widget’s particular container it might be marked as visible, but if some parent container is marked as hidden, then that widget isn’t drawn on screen. Similarly, if that widget is hidden and its parent is also hidden, but then the parent is made visible, that child widget is still hidden.
My general use case is a multi-level hierarchy of actors that are composed of other actors, so this is something I’m having to deal with a lot. Anyway, I’d love to find out that I’m just overlooking some feature of UE4, but if nothing else it’d be good to know I’m not way off in the weeds. Thanks!