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"

What is the right way to share an attribute through multiple

Dear fellow developers,

I'm starting to learn the basics of the engine, and in the process I'm trying to build a high level design document for my game. I'm currently facing a question which I haven't found a sufficient answer to in the conventional "google it" ways. So I'll try my luck here:

In my game I have a bunch of actors, all of them basically share common properties - they all need to move together, in the same speed, towards a common direction. The first thing that popped into my mind was to use components, and assign them as a sub-class to all of the actor instances, but as written in the documentation:

"Contrary to the default behavior of sub-objects in general, Components created as sub-objects within an Actor are instanced, meaning each Actor instance of a particular class gets its own unique instances of the Components"

Thus meaning this might not be the right way to integrate common properties between actors. What is the idiomatic way to do so?

Any help is greatly appreciated!

Product Version: UE 4.18
Tags:
more ▼

asked Feb 12 '18 at 08:02 PM in C++ Programming

avatar image

0rka_
3 1 2

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

1 answer: sort voted first

I've actually been planning a similar system for my project, so hopefully I can be of some assistance here.

It may not be the one and only "right" way, but you could make an actor class that acts as a manager for the group. It would contain a list of the actors it manages and then act as a central location for propagating the target speed and direction to all actors within the group. Depending on your needs, you could have a global one that handles all actors of a given class and its subclasses, or have a more complex system that supports entering and leaving the group and dynamically forming new ones.

For example, say you have a big horde of ZombieActors you want to wander at the same speed in the same direction. You could make a Horde class that holds a list of ZombieActors that have their target speed and direction updated every time you change those settings in the Horde instance. This list could be updated in a number of ways, such as newly spawned ZombieActors finding the global Horde instance and adding themselves, or, for the more complex one, each ZombieActor can hold a reference back to its current Horde, and when they get close to another ZombieActor they can have a check to possibly join that Horde (could be like high chance to join Horde if not in one, low chance if already in one) or create a new Horde if neither is already in one. That does make it get really complex really quick though, because then you have to deal with dynamically combining Hordes so you don't have 100 Hordes of two ZombieActors.

Using an actor as the main manager class has a few benefits, such as having access common events and Tick, but depending on your desired setup, you could actually move the manager itself around and have it act as the target location for the AI in the group. For example, going back to the zombie Horde manager, you could move the Horde actor to something of interest like the origin of a loud noise, and then have all the ZombieActors in its group start moving in that direction.

Also, you might want to take a look at the Crowd Manager section of the Project Settings. I can't find much documentation on it, but from the videos I've seen of it in action, it helps keep groups of AI from getting stuck on each other when moving to the same position or crossing paths.

I hope this helps you out!

more ▼

answered Feb 12 '18 at 10:10 PM

avatar image

Chromarict
337 2 3 8

avatar image 0rka_ Feb 13 '18 at 05:56 PM

The idea of making an actor act as a manager for sub-actors is spot on. Definitely helped my out buddy. Thanks for the great explanation!

avatar image Chromarict Feb 13 '18 at 06:22 PM

Sure thing! I'm glad I could help.

(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