Mass Entity framework questions

Hello,

I’m currently researching Mass Entity/Mass Gameplay systems with Mass State Tree system for my project, so I have some questions regarding their functionality and communication between the systems.

First question is about a proper (Epic’s way) actor’s hydration-dehydration state handling.

I’ve found out that basically everything can be handled using Mass processors and Mass fragments to move around some actor (when streamed-in) or mass entity (when streamed-out) and do some other logic. But what I want to achieve is to have the ability to do some logic on Actors (e.g. AI with some kind of a Brain (AI controller) with a State Tree that will move him around or do other stuff (peaceful, combat behaviours)) when the actors are visible (hydrated state) and when they are streamed-out - use Mass and MassStateTree to do the custom logic for them (dehydrated state) and syncing them during their state change.

From what I’ve tried already - I have a custom RepresentationActorManagement class that I use to sync data from mass to actor in OnPostActorSpawn method (same as in CitySample demo). Also I’ve research the MassTranslator + MassTrait usage to be able to sync mass data with actor when it is visible and vice versa.

But I haven’t found the opposite sync example, when the actor is in destroy process - he syncs all his data with mass and then mass takes control of this entity. I’ve found 2 delegates in MassAgentSubsystem - GetOnMassAgentComponentEntityAssociated and GetOnMassAgentComponentEntityDetaching which can be used to sync actor with mass on actor destroy (second delegate), but I think this will break the architecture and not the ideal way of handling such things. What do you think about such approach? Should this behaviour be custom-made by me, or there is an API that supports such behaviour?

Second question is about the usage of AI Controller’s State Tree Schema along with Mass StateTree Schema.

To provide more context, here is an example - I have one entity that is spawned in some random point on map and is visible (Player stands near the entity). This entity moves using Mass StateTree and now I want this entity to use a custom AI Controller with a State Tree AI that will continue moving my entity and do some other stuff, for example - combat with Player. Then after the combat is finished - this entity must switch back to using Mass State Tree that will move him around some random points once again. How does one implement switch behaviour between State Trees if this is possible? How can I properly stop one tree from executing and restart it when needed (either using a tag or some event with tag)? Should this behaviour also be custom-made? What is the Epic way of doing such things?

Third question is about using Mass as kind of a async backend for AI Controller’s navigation tasks, for example - MoveTo will use Mass to find path and move entity around since the current implementation of AITask_MoveTo is synchronous and not optimal for the large number of simulated entities. This might need some modifications in current Engine code, but the real goal is to make such things less intrusive to the Engine’s code. What can you recommend regarding this?

And the last question is about the way to find all entities in some radius using spatial queries. Looking at the examples at how SmartObjects are found - looks like it has some kind of a wrapper class over hash grid to run queries on and that this solution is specific to smart objects. So it seems that there is no general way to find entities in some grid by radius etc. Should the solution be implemented by me (to have my custom class with hash grid and API to find entities in radius etc) or am I missing something and you already have a solution to this - I just need to look in the right place?

Looking forward to your reply!

- Danylo

[Attachment Removed]

First question is about a proper (Epic’s way) actor’s hydration-dehydration state handling. Second question is about the usage of AI Controller’s State Tree Schema along with Mass StateTree Schema.

I know of several licensees who use a similar approach to this of having MassStateTree run their behaviors while an entity, and then transitioning to an AI controller and StateTree component for behavior when an Actor. I believe you could do this with a state in your Mass ST that does not have any additional logic and waits for a signal to transition back to running any logic. Something like this:

-Root

-Mass Controlled

-Use Smart Object

-Patrol

-Deal with Fire

-Use Actor Brain <- this has no tasks but waits for signal to transition

The only issue would be trying to continue the logic from one to the other when swapping representation. I think the best approach would be to use a task to cause a transition into the relevant state when swapping representation. We have a function for ForceTransition in StateTree, but it was meant for re-entering a state from the same StateTree asset not going from Mass to Actor or vice versa. I think there may be other issues such as trying to continue a SmartObject interaction when changing representation as the behaviors would be different. This would be a wrinkle that would need a lot of attention for how the hand-off between Mass/Actor is handled. You may also want a larger hysteresis buffer for swapping representation to prevent a player from removing the Actor from view then turning back to them to potentially cause a new behavior state to be chosen.

I do not believe we have any example of moving data from the Actor back to Mass when destroying the Actor. I think using GetOnMassAgentComponentEntityDetaching would work to send data back to Mass. You can get the owning actor of the MassAgentComponent and then attempt to cast or get the component that has the data you wish to persist.

Third question is about using Mass as kind of a async backend for AI Controller’s navigation tasks

We did this for the Witcher 4 demo. It uses Mass for navigation and avoidance while using Mover to update the capsule for the characters. So I know it is doable, but I do not know if all the code to support that was added back to the engine. I know part of the Mover code was added in the MoverIntegrations plugin.

And the last question is about the way to find all entities in some radius using spatial queries.

This is something we recently realized had not been added to the engine. We are working on a spatial partitioning system for Mass as it is very needed for proper MassReplication (which is also in development) to work. We are hopeful to make a 5.8 release with the spatial partitioning in Mass, but that could slip further into the future. Mass spatial partitioning should also work with MassNavigation/Avoidance and be usable for more systems, but you may wish to roll your own solution as it is not currently available even from the latest changes in UE5/Main

-James

[Attachment Removed]