How to procedurally create widgets with dynamic content for each widget

Im making a game on Andriod
I need to create a profile selection screen with a scroll box

How to procedurally create widgets with dynamic content, like each profile has its own content from this…

To this…

I know how to bind the star count, word count, and player name that’s not the problem but with a scroll box populate the scroll box with widgets for each profile.

Can someone by example or pseudocode explain how it’s done?

Can someone by example or pseudocode
explain how it’s done?

  • create a widget representing a profile, expose variables or a struct
  • and then in the parent container:

Ideally, you’d keep the profiles in a struct array and loop through that array, creating widgets & piping in data. Widgets can bind plain variables but can also poll from structs:

Very handy.

2 Likes

Forgive me but how do I make a struct array?
I don’t see it here

How did you do this, add variables to Create Widget node

346248-2.jpg

And I don’t get the last image?
I do get the first image but don’t how you did somethings

Lets say this is your profile widget:

346249-screenshot-4.png

So you have text boxes and images bound to the elements in that struct. This struct variable is flagged Instance Editable and Exposed on Spawn. This way those variables appear on the node when the widget is instantiated.


The parent widget that hosts the scrollbox has an array of structs that define profile data.

346250-screenshot-3.png

So you can loop through that array and pump the data into each widget.

1 Like

Thank you for your help I have 1 more question
I’m using multiple profiles and using a game instance for each profile and saving and loading the profiles with a Struct Array and a Profile struct on the game instance and the save game class.

346277-savegame.jpg

346278-instance.jpg

But as I’m coding I see some problems.
By having the ProfileArray on each profile save if I delete a profile or make a new one how do I update all the profiles. is there a way to have the profile array separate that affects all the saves?

how do I update all the profiles

I’d say you’ve got 2 choices:

  • Clear the scroll box and recreate all profile widgets

  • get all Scroll Box children, Loop → Cast → Update the struct variable. Discard excess widgets if you have more widgets than profiles at this point.

I’d only recommend the second method if you really cared about performance, let’s say we have thousands of profiles to update. It’s faster to update 1000 than create 1000. And if you really wanted something efficient, I’d abandon the scrollbox and look into the List View widget - super speedy but somewhat convoluted to set up.

yea, but do I need to loop over the game saves to update the profile array on each save, or is there a better way?

Yes, if you need to update a save game, you need to load it, update what’s needed, save it back. Once you’ve paid the upfront cost of setting it up, it’s pretty straightforward. But you know that probably.

is there a way to make a persistent struct array that I don’t have to load or save? when the game loads with no save loaded yet the screen is blank. because I need the profile struct array before I load a game

I’m stuck on dynamic user input profiles. I need a way to make ProfileArray persistent or making the array add node to keep the values the user adds. it seems that it resets when the game shuts down. and I load it again and it’s like I didn’t add anything to the Profile Array

Sure. It’s just an array of structs you can manually populate with whatever you need. I assume you need some dummy data, right?

Well, if you need something persistent, you need to store in a save game. You cannot have something persist between the game sessions without saving.

Are you saying that when you save & then load data, the data is not correct? Operating on arrays of structs can be very tricky as BPs copy a lot of data. Look at the icon on the For Each Loop node - it’s a dot - that’s a copy of the data. A diamond represents data passed by reference.

You need to ensure you pass data by reference and, in certain scenarios, additionally push the data back into arrays.

Sure. You can have multiple arrays of structs in a save game as separate variables. Also, nothing really stops you from having and array of struct arrays containing arrays of struct arrays containing struct arrays… you get the gist!

It just becomes more difficult to update. It’s a pretty normal way of working if you have a multi-layered procedural generation that you need to save and restore.

I’ve gone as deep as 7 nested structs arrays. Is it fun - no? Is it pretty - hell, no! Does it work - yeah.

can I have 1 save but have different profiles?

I got everything working except switching profiles the profile doesn’t want to switch. for some reason, my get array command doesn’t get.

It seems when making the profile the first time it doesn’t increment 1 reliably by adding to the profile index.

Here is the game instance but I don’t think its part of the problem

edit
Sorry After some more testing it might increment 1 but doesn’t load the correct profile at the correct index

I finally got it to work! Thank you for all your help!