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());
BuildZones.Add(NewBuildZonesInfo);
}
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.