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:
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!
asked Feb 12 '18 at 08:02 PM in C++ Programming
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!
answered Feb 12 '18 at 10:10 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here