Custom MassStateTreeSchema and its usage with MassStateTreeTrait

Greetings!

I’m using a custom Mass State Tree Schema class that allows the common state tree structs and also my own custom structs (which are basically derived from the mass state tree ones) to be able to use only custom tasks, evaluators etc. The problem is - I can’t use StateTree with a custom MassStateTreeSchema in a MassStateTreeTrait because it requires the concrete asset data tag :

UPROPERTY(Category="StateTree", EditAnywhere, meta=(RequiredAssetDataTags="Schema=/Script/MassAIBehavior.MassStateTreeSchema"))
TObjectPtr<UStateTree> StateTree;

This isn’t working for custom schemas as they have another name (which is obvious) and for example can be placed in some kind of a separate plugin for reuse in different projects.

To overcome this obstacle - I had to create a custom MassStateTreeTrait that is a copy-paste of the default one, but using another “RequiredAssetDataTags” to support my custom schema. I don’t want to go with this solution as I’ll have to support this code on each engine version updates, just to be the same as the default one, but with another asset tags requirement.

So my questions are - how does one can use StateTrees with custom mass schemas in MassStateTreeTrait? How can I override the strict rule of having a proper asset data tag for my StateTree? Are there any plans on changing the current Trait’s behavior to support such customizations? How to do it properly using your code as a base to prevent future merging hell scenarios?

Looking forward to your reply!

Best regards,

Danylo

[Attachment Removed]

Hi there,

Unfortunately there isn’t an easy solution for getting around this. Modifying the engine /plugin’s source code would be the most robust approach.

There is a more hacky workaround that is easier to implement but could lead to issues down the line. You can get around required asset tags limitation by creating a new asset from the drop-down menu when selecting the state tree for your trait. This will allow you to select any schema type. Through some rudimentary testing it doesn’t seem to cause any issues with mass AI. However it could potentially lead to unintended behavior.

The reason this is possible is because the “RequiredAssetDataTags” specifier only limits what assets are available in the asset picker. It doesn’t actually prevent you from setting the value of the property (Except through the editor UI). If this works for you, you might have some success setting the value manually through code which would be more robust than having to create a new asset each time.

I can’t speak to the developers intention or whether this will be changed in the future. Although due to the mass plugin’s experimental/beta status it is possible. If you want more insight into this I can re-assign this case to a subject matter expert.

- Louis

[Attachment Removed]

Hello!

Thanks for your answer, I’ll try your solution, but if I fail - I’ll switch back to using default Mass Behaviour Schema and maybe build my custom tasks there.

- Danylo

[Attachment Removed]

No worries,

If you have any luck it would be great to hear how your implementation went.

I will close this case for now but feel free to reply in the future.

Cheers,

Louis

[Attachment Removed]