Announcement

Collapse
No announcement yet.

[UMG] iterate through canvas elements

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

    [UMG] iterate through canvas elements

    I have a Canvas panel widget that already contains objects. I need to iterate through each item in the container. The exact order does not matter as long as I get each contained item as a unique member of the set. The exact type of the returned object does not matter either. For now it has to be a Canvas. How would I use a foreach loop to extract each object? As far as I know a Foreach needs an array input and I'm not able to find out how to get the children of the Canvas in array form. I know as a senior programmer of over 30 years that all containers of multiple objects use either linked lists or arrays (actually a specialized linked list with implicit linking) to store their content. The fact that a Canvas has "Get Child At" and "Get Child Count" is evidence of that. How do I get that array and not just its elements?

    #2
    Hey. I was curious so I tried to find a solution.
    Found a workaround.
    Click image for larger version

Name:	canvas.PNG
Views:	1
Size:	94.2 KB
ID:	1097285

    Comment


      #3
      Yep. I did consider the issue of using a for loop. I've looked at the structure of ForEach and it's a macro. Guess what it essentially does? It has an implementation of a for loop (I imagine looking at For will give equivalent results). But this exercise revealed a gap in the implementation of UMG. There should be no reason a read-only version of panel contents in array form shouldn't be available. That's how C# implements foreach anyways. Good attempt though. You can get the count of children in the panel instead of using a hard-coded value there. If you uncheck the context option in the editor and do a search on foreach you will get a foreach version for editing and for a large list of enums, but nothing for base container classes. I'm guessing you are using the array add as an example of your loop's use - at least I hope so! Just using your method to pass it to a foreach would be excessive computationally.

      Click image for larger version

Name:	2015-12-19 (1).png
Views:	1
Size:	254.7 KB
ID:	1097287
      Last edited by Avelworldcreator; 12-19-2015, 10:25 PM.

      Comment


        #4
        Unfortunately there is nothing that allows you to do directly what you want out of the box in blueprints. Since you are a programmer, I suggest that you look into creating your own function to do this in C++, as that should be relatively simple.
        Marketplace Assets

        Advanced Mobile Input: Marketplace Page | Support Thread ――― Easy Input Remapping: Marketplace Page | Support Thread
        Multiplayer Blueprint Chat System: Marketplace Page | Support Thread ――― Closing Credits System: Marketplace Page | Support Thread
        Minesweeper Template: Marketplace Page | Support Thread ――― Maze Creator: Marketplace Page | Support Thread

        Comment


          #5
          Originally posted by Jamendxman3 View Post
          Unfortunately there is nothing that allows you to do directly what you want out of the box in blueprints. Since you are a programmer, I suggest that you look into creating your own function to do this in C++, as that should be relatively simple.
          Actually it's demonstrably possible to do in Blueprints. That was the point of this exercise. Unfortunately I wish it were really that simple in C++. You've directly seen my UI work in remote view - you know my level of competency. (And, yes, the chat is coming along nicely; this is another part of the UI).

          Comment

          Working...
          X