How can I add a struct with a dynamic name to an array?

Hey, you can make a local struct and add it. something like this

 for(c = 0; c < 36; c++)
    BuildZonesInfo AddedBuildZonesInfo;
    //Set BuildZoneINfo values here

Or you could set up a Struct constructor and just call it before adding it to the Array

BuildZonesInfo AddedBuildZonesInfo(constructor values);

I really didn’t know how to ask this question in one sentence, so I’ll just explain:

I have a struct containing some vectors, and I want to make an array of this struct. The problem is I have a ton of structs to create and add, and I don’t know how to automate this process.

I have a struct called BuildZonesInfo and an array called BuildZones.

I have 36 structs called “spots” so I have “spots(1-36)”.

I tried doing something like this:

for(c = 0; c < 36; c++)
BuildZones.Add(spots//+whatever c is currently);

Is there a way to automate this process, or do I have to just copy and paste 36 lines of adding them to my array?

I’m not against doing this because it’s too much work, but I’d like to know if it’s possible just so I know in the future.

Dynamic variable naming is not something you can do at runtime. There are preprocessors that can do this for you but I highly advise not using that method.

It sounds like you need to restructure your code as having 36 different variables isn’t a good thing. What you should do is something like the following:

for (int32 c = 0; c < 36; ++c)
    BuildZonesInfo NewBuildZonesInfo(c, FVector(), FVector(), FVector());

c is the ID, and FVector() represents an arbitrary FVector that can come from either a method parameter, method return value, or whatever. This way you can have any arbitrary number of structs and you can access any one of them by searching the array for the element with the correct ID.

This is what I’ll probably do. Thanks!