Creating a data struct for every floor in my house builder

Hello!! So I am currently working on a house builder and I’ve made a data struct with variables such as


Now I plan for my house builder to also have the ability to make multiple floors, is there a way I can have the data struct for every floor individually?

You could just make a variable into an array with the variable type being the struct. Then for each floor, you’d get struct where index= floor number ( probably +1 unless you want a floor 0 lol).

1 Like

So you mean something like this?

Actually, I think this could work as well…

Basically. Though a for and foreach loop is a bit redundant. On the for loop there, you could get the array length subtract 1 and plug the result into the last index pin. Likewise, in the construction script, you could use use the array length -1 to set number of floors, and when you add a floor in game, you would add an element to the array for the new floor, then use the new length -1 to update the number of floors var.

Sorry I’m having a really rough time trying to visualize this, is it possible you could share the BP or node system you’re talking about here?

Sure.

Looping through struct array:

Mostly empty function to add a floor to array:

1 Like

And what is the first for loop connecting into? Is it a for each loop for the array or whatever the remaining house builder script is?

EDIT: Okay so I’m a little lost again… would I need to use a For Each Loop node still to set my variables? or should I just do something like this…

The for loop I posted just continued to some dummy code to set the relative location of a placeholder static mesh for a door. This loop would be a good place to set locations and/or add mesh components for the floors’ props.

No need to for each inside the loop, since it’s already stepping through the whole array. To set the vars inside each floor’s struct, you’d just use a SetArrayElement node and grab the index off the for loop to use the current floor as the index for the element to set.

Oh okay, yeah thank you. I was getting confused because I had a slight issue in my script that I made while setting variables lol

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.