Announcement

Collapse
No announcement yet.

Iterating over children of panels in UMG

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Iterating over children of panels in UMG

    I'm working on the frontend of a game using UMG and predominantly blueprints. There's a number of occasions where I've needed to iterate over all of the children in a derived Panel Widget to perform some operation in blueprint (eg. deselect all items in a Horizontal Box of radio box items because a new one is selected).

    However, every time I do this, I can't find any other way than to effectively build up a numeric for-loop in the blueprint using UPanelWidget::GetChildrenCount() and GetChildAt(...), something that comes out quite verbose and garish if trying to implement using blueprints:
    Click image for larger version

Name:	widget_iteration1.png
Views:	2
Size:	101.3 KB
ID:	1192257

    What I was thinking about was implementing a simple, one-stop GetChildren() function on UPanelWidget to expose a non-index based method that can be hooked up straight to a ForEach in blueprints, in a consistent location with the rest of it's UPanelWidget's child management logic, providing simpler child traversal functionality to all UMG panels (scrollboxes, h-boxes, etc.):
    Click image for larger version

Name:	widget_iteration2.png
Views:	2
Size:	71.0 KB
ID:	1192258

    However, before thinking about "giving back" to the Engine, I wanted to check with the developers/community that I've not missed anything obvious.
    There's not some alternative way of doing this simply, which is already implemented, is there?

    NB. I did find several forum posts in the past asking similar questions (eg here); the only solid recommendation I could find was to call WidgetTree() on the object, which returns an instance of the UWidgetTree transient utility class used for child traversal. However, this is specific to UUserWidget; it's not implemented in UPanelWidget or any of its derived classes. Additionally I know there is the GetAllWidgetsOfClass library function, however this of course operates at the viewport level.

    #2
    Had similar situation, so I just created a global macro - ForEachChildWidget().

    I use that for immediate children.
    For children beyond that, I created a C++ class GetChildrenOfClass(), which I donated to Rama's great plugin.

    If the parent widget only has one layer of children, GetChildrenOfClass() would work for it.
    If it has multiple layers, it'll find all of them
    Rule#21: Be polite, be professional, but have a plan to kill everyone you meet.

    Comment


      #3
      Thanks Kris - that at least redeems that I've not lost it and missed something obvious. It's nice to hear someone else has been through the same thing!

      It makes me a bit reluctant making a contribution considering I now know there's an alternative. Nice one on contributing to RGP; your work sounds like it provides a much richer implementation and a method for "spidering" across children-of-children. However it strikes me that at least a simple call is missing from the vanilla Engine classes. What I'd really like to see is that someone getting started with the Engine doesn't have to go through the research that we had to do - it's just there, ready to use in the PanelWidget; off they go and blueprint it up.

      I guess what really trying to gauge is, is it worth me making a pull request in an effort to help others out in future?

      Comment


        #4
        If you feel it is of value, it can't hurt.
        But I suggest you do as I do, and create one for Rama's VictoryPlugin as well.
        You can always ask people if they are interested in the thread for it before hand.
        In that way, even if it doesn't make to the engine level due to reasons, people can still grab it from a popular alternate source.

        You could create your own Blueprint function library and distribute that, but that leads to yet another library/plugin people need to grab.
        Rama's VictoryPlugin is is essentially the "go-to" library for extra Blueprint nodes.
        Rule#21: Be polite, be professional, but have a plan to kill everyone you meet.

        Comment

        Working...
        X