I’m working on a realtime open world campaign game, where the world is divided into several regions. Each region then has its own flags which the team needs capture in order to capture the whole region. I have an actor class for both the region and the flag, and what I want to do is add instances of flags placed in-game to the region they belong to. Hope this makes sense…
Although, I know I could just give each flag inside of the region a unique ID, and loop through all of them in order to get the number of flags captured, etc. But my question is if it is possible for me to add the instances of all the flags inside the region-actor to an array belonging to the region-actor? That way I could easily get an element of the array and access capture progress, owning team, etc. directly from the region-actor and everything would be so much easier!
Please notify me if something is unclear, this functionally of the game is basically what it’s all about, so I’ll do my best to make this understandable.
Thanks in advance!
Do your flags have some kind of concept as to which region they’re supposed to belong to? I.e. Flag A knows it belongs to the “Red Region” and Flag B know it belongs to the “Blue Region?”
If not, do / could your regions have some kind of collision geometry that defines their bounds?
I would probably have one array in the game mode or somewhere similar which tracks all flags, so as they are spawned they are added to that array.
For me, the array would probably be a type AFlag which inherits from AActor, or it could be a struct or a simple class. In either case you should track
- Flag Instance (AActor or whatever your flag type is - This isn’t necessary if your array is of type AFlag, as the element is the flag instance)
- Flag ‘Owner’ (Int, Enum or some other type which identifies the original owners such as Blue, Red)
- Flag ‘Possession’ (Int, Enum as above, but this time it indicates who has possession now).
You could also use a TMap or a TSet depending on exactly what you want.
You can now perform simple loops through the list / set / map which will allow you to check how many flags exist and how many of them have been captured etc.
No, the flags only have an ID to specify its name. I could make a new variable to also specify the region it belongs to, but then all the flag-IDs would have to be unique, and that’s not what I want.
Let’s say we have two regions, “Castle” and “Farm”. Each of these regions then has its own flag, “Flag A”, which means there’s now two flags with ID Flag A in the level. What I’m really asking is, if I could make an array in the region-actor storing only the flags inside it. So the flag-array of “Castle” would store the instance of the flag-actor placed in the “Castle”-region.
Also, I do have collision/borders which defines the regions, yes. Hope this cleaned it up, thanks
What I’ve done now is I’ve added a “RegionID” variable to the flag-actor. Then, in the game mode, I’m looping through all regions and for each region I’m looping through all flags to check which region they belong to. If the regions match I add the instance of the flag to an array owned by the region, and this absolutely works!
I believe this is exactly what I’m trying to approach. Although, if I loop through all flag-actors placed in the game and add them to an array, will it add them as an instance or as the parent actor? Because this is what I’m having issues with. I don’t know how I would add instances of an actor to an array…
Thanks! I will definetly try this