I am dynamically adding children to the grid panel based on an event trigger. When the event triggers, it will:
Create an element
Add child to grid
Set column to current number of elements in grid (effectively appending the element to the end of the list)
Set row to 0
Set vertical align to fill
Set horizontal align to fill
Increment grid element count
Case 1: If I start the game with 0 elements in the grid panel, and I trigger the event, a single element gets added to the grid panel. However, upon triggering the event again, everything in the blueprint gets fired, but there is no newly added grid column.
Case 2: If I start the game with 2 “dummy” elements in the grid panel by setting them in the designer and properly set their column number, I can trigger the event and it will properly add 2 elements if I trigger the event 2 times, but no more than that.
If I setup 6 “dummy” elements in the designer with proper column assignments, I can trigger the event 6 times and get 6 “replacements” when my blueprint runs, but no more. … and so on.
Because it appears the grid doesn’t grow beyond the initialized number of elements (starting with 1 slot?), how can I dynamically allocate and add new elements to the grid?
In-game after getting a status effect - the thing to note here is the Icon, not the text. The text has nothing to do with the grid. Additional status effect icons don’t get added with the current code, unless I add “placeholder” images for each icon I want to add.
version 4.5.1
I have a simple object on the ground. Upon walking over it, the player will get a status effect applied to them. The character has an event trigger for when the character is a recipient of a new status effect. This will be reflected on the UI as an expanding list of icons. A row of status effect icons on the UI will display icons for each status effect the player currently has affecting them.
After doing to digging I found a project that I was working on that does something very similar to what you are trying to accomplish. I create a blueprint with a block in it that the player walks over and it will then add an image to the top left. As the player walks over more of the blocks it adds images in a single row across the top of the screen. This way you could have one version of every icon you need in your widget and just call the image needed when an item in the world is walked over or what have you. I feel that this would be a good starting point for you. I have also attached a my blueprints via Notepad (simply copy and paste them) [PickUpBluePrint][1], [My Character][2] . I hope this helps.
The actor blueprint pickup that is placed in the world:
Thanks for the screenshots. They’re a help because they indicate to me that I need to drop my use of the Grid Panel (perhaps I didn’t understand its use) and implement the grid organically instead, as you have done in your blueprints.
I’ll likely home-grow a “grid” class in C++, and put all of the grid-related code behind the scenes so that I can simply call a blueprint callable like “Add Buff Icon”, passing it an image widget and what not.
I just wanted to say that I swung back ground and played with the grid canvas again because it just didn’t make sense to me that I had to do canvas calculations manually, and determined this is the solution I was looking for:
Make a Uniform Grid Panel in the main HUD BP/Designer in UMG and makesure “Is Variable” is checked.
Set settings to “Size to Content”. I added some padding in Slot Padding as well
Add a single “Dummy” image as a child. Set it’s size to how big you want your icons to be, and set it to invisible.
In a blueprint where you want to dynamically add slots, just call Add Child to Uniform Grid with your grid panel as the target and your icon-widget as the content.
Take the return value of “Add child to Uniform Grid” and set it’s column to an incremented value, set it’s horizontal and vertical alignments to fill.