Megafunk / MassSample

My understanding of Unreal Engine 5's experimental ECS plugin with a small sample project.
MIT License
681 stars 112 forks source link

Add Filter options to FMassSmartObjectHandler::FindCandidatesAsync #31

Open Ji-Rath opened 2 years ago

Ji-Rath commented 2 years ago

Currently, when using FMassSmartObjectHandler::FindCandidatesAsync, it is only possible to specify a location to find smart objects. There is no way to filter smart objects or even set a distance, since it is determined in the processor - meaning the distance can be set globally in the project settings but the filter will only look for smart objects with USmartObjectMassBehaviorDefinition.

I believe this is an issue because by default the FMassSmartObjectRequestResult only holds 4 candidates (as a constexpr) so even if you were to try and filter after finding the candidates, it is possible that nothing will come back and you will have to try again.

A suggestion would be to let FindCandidatesAsync have a FSmartObjectRequestFilter input to let each request filter out unwanted smart objects. This can also be done with distance so it is possible to input a distance to find smart objects.

Finally, adding the features above would allow the Smart Object Eval evaluator to have some more values to change for flexibility.

As an alternative, it is always possible to simply call FindSmartObject() from the SmartObjectSubsystem which includes a filter and ability to find candidates in a range. It is also possible that I am not using the tasks/functions as intended since this is still in development. Please let me know if I was too vague or if there are any questions.

Ji-Rath commented 2 years ago

Just to add a quick comment, I noticed the same issue with FMassSmartObjectHandler::ClaimSmartObject where there is no option to specify a filter. This means it is not possible claim smart objects using FMassSmartObjectHandler unless all tags are default and the behavior derives from USmartObjectMassBehaviorDefinition

Edit: I think this outlines an interesting find with how this particular system requests smart objects. It performs a slot check for the smart object when searching. If a slot in the smart object is valid, it only returns the smart object. This means when claiming, it performs a check again to see whether a slot is available for the smart object using the same default filters.

sirjofri commented 2 years ago

It would be great to have the filter option based on gameplay tags and/or MassBehaviorDefinition class. Furthermore, it would make sense to add these fields to the StateTree SmartObject Evaluator, too.

It's quite bulky to write a filter separately (and error prone), and for (probably) many use cases the status quo would mean, copying the existing solution and adjust (or make engine changes).

So yeah, please add the filter solution.

sirjofri commented 2 years ago

Just to add a quick comment, I noticed the same issue with FMassSmartObjectHandler::ClaimSmartObject where there is no option to specify a filter.

I think this is not a bigger issue when working with StateTrees btw. The ClaimSmartObject task has the request result of the SmartObject Evaluator as an input, and it just takes the first, if possible. So if you filter the candidates in the evaluator, ClaimSmartObject task can only claim a filtered task.