x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Add instances of actor to array

Hello,

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! :)

~Stefan

Product Version: UE 4.19
Tags:
more ▼

asked Jul 11 '18 at 08:54 PM in C++ Programming

avatar image

Steferich
57 3 2 8

avatar image DarkwindRichard STAFF Jul 11 '18 at 09:43 PM

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?

avatar image Steferich Jul 12 '18 at 07:39 AM

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 :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Jul 11 '18 at 10:06 PM

avatar image

phil_me_up
984 4 6 12

avatar image Steferich Jul 12 '18 at 07:44 AM

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 :)

avatar image Steferich Jul 12 '18 at 08:01 AM

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!

Thanks alot! :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question