[StateTreeEditorModule] Register a custom UStateTreeEditorSchema to a UStateTreeSchema

Hello,

I noticed that the StateTreeEditorModule allows to register a specific UStateTreeEditorSchema to a UStateTreeSchema with :

RegisterEditorSchemaClass / UnregisterEditorSchemaClass. Unfortunately, those methods were not exposed for usage so I exposed them with UE_API in order to use them in my project.

This allows me to bind a specific editor schema to my runtime schema and add some specific validate/compile rules to my StateTrees. Unfortunately I noticed crash at boot of the editor if some SateTrees have already been created with my UStateTreeSchema but previously using the default UStateTreeEditorSchema.

In UStateTreeEditingSubsystem::ValidateStateTree, in the FixEditorSchema migration branch was trying to rename the previous editor schema with itself as outer: PreviousEditorSchema->Rename(…, PreviousEditorSchema, …). That can corrupt object path handling and leads to a serialization assert on my side. So I made the following fix :

Previously in \UE\Engine\Plugins\Runtime\StateTree\Source\StateTreeEditorModule\Private\StateTreeEditingSubsystem.cpp L.224 :

PreviousEditorSchema->Rename(*TrashName.ToString(), PreviousEditorSchema, RenameFlags);

I replaced with :

PreviousEditorSchema->Rename(*TrashName.ToString(), GetTransientPackage(), RenameFlags);

I don’t know why those methods were not exposed as RegisterEditorDataClass/ UnregisterEditorDataClass are well exposed and if it’s right crashfix but it fixed the issue on my side.

Thanks !

We added a CL a few months back to export both of those functions. The CL is in UE5 Main stream at CL# 46778994. It also includes a fix for a crash when updating the schema. Would you be able to cherrypick that CL and test if it is working for you? It is possible our fix does not account for your case.

-James

Hello James,

Thanks for the information !

Unfortunately, we won’t be able to cherrypick that CL now but I keep an eye on it to check if it well fix our crash too in our future integration.

You may look at the changes to make locally even without a cherrypick to reduce some potential merge issues in the future. The CL does mention fixing some bugs, but as you find any more, please let us know as we want to cover all the use cases.

Thank you for bringing this to our attention! This particular one had a CL already, but it is great to know what arises in other projects.

-James