No Interface to Assign Modular Control Rigs in Sequencer with Blueprint

To procedurally spawn ControlRigs in the sequencer through custom commands (needed to populate cinematic scenes automatically) we are using the interface provided by Editor Function Libraries, specifically Find or Create Control Rig Track and Expose Control Rig Components nodes requires a ControlRigClass to instantiate with each ControlRig being its own class child of Control Rig. below:

But to instantiate Modular Control Rigs. Modular Control Rigs are all of type ControlRigRuntimeAsset, they are pure data payload, so it is not possible to cast them to a ControlRig class and pass them to this node.

There is no alternative interface provided to be able to do this with Modular Control Rig; not in Blueprint, not in Python.

This is currently stopping us from fully rolling out Modular Control Rigs to our pipeline, as we are not able to integrate them in our procedures, but only creating them manually through the Editor UI.

Is there another way to do this or is this a limitation?

Thank you

Sergio

[Attachment Removed]

Steps to Reproduce
Use Find or Create Control Rig Track and Expose Control Rig Components nodes

[Attachment Removed]

Hey there,

I’ve logged an issue that you can follow. https://issues.unrealengine.com/issue/UE-400417

We are working on this, but there are parts that are not complete and not available to integrate into 5.8 yet. Optionally, you could write your own helper function to bypass the lack of exposure. Would you like the code or pseudocode for that?

Dustin

[Attachment Removed]

Hi Dustin,

Yes please the code would be very useful.

Thank you!

[Attachment Removed]

This is a pretty all-inclusive function. I’ve tested it and it works ok.

/*CPP FILE. I put it in UControlRigSequencerEditorLibrary, but you could put it in a different spot.*/
 
UMovieSceneTrack* UControlRigSequencerEditorLibrary::FindOrCreateControlRigTrackFromAsset(UWorld* World, ULevelSequence* LevelSequence, UObject* ControlRigAsset, const FMovieSceneBindingProxy& InBinding, bool bIsLayeredControlRig)
{
	// Accepts runtime assets (such as Modular Rigs) as well as Control Rig Blueprints and classes
	FControlRigAssetStrongReference Source(ControlRigAsset);
	if (!Source.IsValid())
	{
		if (FControlRigAssetInterfacePtr EditorAsset = ControlRigAsset)
		{
			Source = EditorAsset->GetRuntimeAssetInterface().GetObject();
		}
	}
 
	UMovieScene* MovieScene = InBinding.Sequence ? InBinding.Sequence->GetMovieScene() : nullptr;
	if (!Source.IsValid() || !LevelSequence || !LevelSequence->GetMovieScene() || !MovieScene || !InBinding.BindingID.IsValid())
	{
		UE_LOGF(LogControlRigEditor, Error, "FindOrCreateControlRigTrackFromAsset: Need valid parameters");
		return nullptr;
	}
 
	const FMovieSceneBinding* Binding = MovieScene->FindBinding(InBinding.BindingID);
	if (!Binding)
	{
		return nullptr;
	}
 
	TArray<UMovieSceneTrack*> Tracks = MovieScene->FindTracks(UMovieSceneControlRigParameterTrack::StaticClass(), Binding->GetObjectGuid(), NAME_None);
	for (UMovieSceneTrack* AnyOleTrack : Tracks)
	{
		UMovieSceneControlRigParameterTrack* Track = Cast<UMovieSceneControlRigParameterTrack>(AnyOleTrack);
		if (Track && Track->GetControlRig() && Source.IsSourceOf(Track->GetControlRig()))
		{
			return Track;
		}
	}
 
	if (bIsLayeredControlRig && Source.GetRigClass() != UFKControlRig::StaticClass() && !Source.GetSupportedEvents().Contains(FRigUnit_InverseExecution::EventName))
	{
		UE_LOGF(LogControlRigEditor, Error, "Cannot add an additive control rig which does not contain a backwards solve event.");
		return nullptr;
	}
 
	FSlateApplication::Get().DismissAllMenus();
	UMovieScene* OwnerMovieScene = LevelSequence->GetMovieScene();
	TSharedPtr<ISequencer> SharedSequencer = GetSequencerFromAsset();
	LevelSequence->Modify();
	OwnerMovieScene->Modify();
 
	FScopedTransaction AddControlRigTrackTransaction(LOCTEXT("AddControlRigTrack", "Add Control Rig Track"));
 
	UMovieSceneControlRigParameterTrack* Track = Cast<UMovieSceneControlRigParameterTrack>(OwnerMovieScene->AddTrack(UMovieSceneControlRigParameterTrack::StaticClass(), InBinding.BindingID));
	if (!Track)
	{
		return nullptr;
	}
 
	FString ObjectName = Source.GetName();
	ObjectName.RemoveFromEnd(TEXT("_C"));
 
	UControlRig* ControlRig = Source.CreateInstance(Track, FName(*ObjectName), RF_Transactional);
	if (!ControlRig)
	{
		UE_LOGF(LogControlRigEditor, Error, "FindOrCreateControlRigTrackFromAsset: Failed to instantiate %ls", *Source.GetPathName());
		OwnerMovieScene->RemoveTrack(*Track);
		return nullptr;
	}
 
	ControlRig->Modify();
	if (UFKControlRig* FKControlRig = Cast<UFKControlRig>(ControlRig))
	{
		if (bIsLayeredControlRig)
		{
			FKControlRig->SetApplyMode(EControlRigFKRigExecuteMode::Additive);
		}
	}
	else
	{
		ControlRig->SetIsAdditive(bIsLayeredControlRig);
	}
	ControlRig->SetObjectBinding(MakeShared<FControlRigObjectBinding>());
	ControlRig->Initialize();
	ControlRig->Evaluate_AnyThread();
 
	if (SharedSequencer.IsValid())
	{
		SharedSequencer->NotifyMovieSceneDataChanged(EMovieSceneDataChangeType::MovieSceneStructureItemsChanged);
	}
 
	Track->Modify();
	UMovieSceneSection* NewSection = Track->CreateControlRigSection(0, ControlRig, true);
	NewSection->Modify();
 
	Track->SetTrackName(FName(*ObjectName));
	Track->SetDisplayName(FText::FromString(bIsLayeredControlRig ? ObjectName + TEXT(" (Layered)") : ObjectName));
	UControlRigSequencerEditorLibrary::MarkLayeredModeOnTrackDisplay(Track);
 
	if (SharedSequencer.IsValid())
	{
		SharedSequencer->EmptySelection();
		SharedSequencer->SelectSection(NewSection);
		SharedSequencer->ThrobSectionSelection();
		SharedSequencer->NotifyMovieSceneDataChanged(EMovieSceneDataChangeType::MovieSceneStructureItemAdded);
		SharedSequencer->ObjectImplicitlyAdded(ControlRig);
	}
 
	FControlRigEditMode* ControlRigEditMode = static_cast<FControlRigEditMode*>(GLevelEditorModeTools().GetActiveMode(FControlRigEditMode::ModeName));
	if (!ControlRigEditMode)
	{
		GLevelEditorModeTools().ActivateMode(FControlRigEditMode::ModeName);
		ControlRigEditMode = static_cast<FControlRigEditMode*>(GLevelEditorModeTools().GetActiveMode(FControlRigEditMode::ModeName));
	}
	if (ControlRigEditMode)
	{
		ControlRigEditMode->AddControlRigObject(ControlRig, SharedSequencer);
	}
	return Track;
}
 
/*HEADER FILE*/
 
/**
* Find or create a Control Rig track from a Control Rig asset based upon the binding
* @param World The world used to spawn into temporarily if binding is a spawnable
* @param LevelSequence The LevelSequence to find or create
* [Content removed] Control Rig Blueprint or Control Rig class
* @param InBinding The binding (actor or component binding) to find or create the Control Rig track
* [Content removed] the Control Rig is added as a layered rig
* @return returns Return the found or created track
*/
UFUNCTION(BlueprintCallable, Category = "Editor Scripting | Sequencer Tools | Control Rig")
static UE_API UMovieSceneTrack* FindOrCreateControlRigTrackFromAsset(UWorld* World, ULevelSequence* LevelSequence, UObject* ControlRigAsset, const FMovieSceneBindingProxy& InBinding, bool bIsLayeredControlRig = false);
 
/**

Because this is a UFUNCTION you could call this frrom python. If you follow the above placement it would something like:

unreal.ControlRigSequencerLibrary.find_or_create_control_rig_track_from_asset(world, seq, rig_asset, binding, False)With the properties being pretty self explanatory in terms of unreal types.

Dustin

[Attachment Removed]

Thanks, for your reply, we are waiting for our technical artist team to have availability to compile and test this.

In the meantime we wanted to bring your attention to another quirk introduced between 5.6 and 5.8 which is affecting us and our workflow.

Control rigs in earlier versions used to be of type Control Rigs Blueprints.

From 5.8. Control Rigs AND Control Rig Modules AND Modular Control Rigs in Unreal are created as Control Rig Runtime Assets and NOT as Control Rig Blueprints. Creating a Control Rig through the editor UI will force this new type and won’t it allow you to chose between the two. As far as we know Epic did this to enforce the usage of Control Rig Runtime Asset as it seems to perform better (like the name says) at runtime.

So far so good, except is a big problem if one is trying to do anything procedural in the sequencer or is planning on NOT using epic default control rig content.

Let’s dive into why:

1) (This is what our ticket is was originally about) Blueprints nodes which handle creation and assignment of Control Rigs to Sequencer binding don’t work with Control Rig Runtime Assets cause they only accept types of Control Rig Blueprints. An example of this is Find or Create Control Rigs or Assign Control Rig in the Editor Function Library.

2) If you go to Project Settings, in the section where you can assign the Default Root Module for Modular Rigs you won’t be able to assign Control Rig Runtime Assets (meaning you can’t assign any Control Rigs Modules you have created in 5.8 cause they won’t be of the right type).

3) If you look closely at the default content provided by Epic (e.g. Manny Control Rigs, or the Epic Control Rig Modules) you will discover that they are still of Control Rig Blueprint type. This points to the fact that they are legacy content created with earlier version and ported. These will all still work with the Blueprint nodes and are accepted by the Project Settings slot.

In essence if one wants to work with Control Rigs procedurally they are stuck with using default content and can’t even make “legacy content” of old class types which would be compatible. And if one wants to use both it becomes even more complicated.

The next question is: “How does one create Control Rig Blueprint assets if really really needed”? You can’t through the UI as far as we tried, cause the editor is enforcing Control Rig Runtime Asset as type.

So far we thought of: A) Create them in an earlier version of Unreal and port them, B) Copy from Epic default Control Rig content, wipe it of all the nodes, re-assign the skeleton and start with an empty Control Rig, 3) Potentially one could export the Control Rig Runtime Asset as text, change the class type in the text file and then re-import the asset but we have not yet tested this.

Any suggestion, insight or workaround is appreciated.

[Attachment Removed]

Hey there,

This most likely stems from the changes we’ve made to some of the foundations to control the rig, and the new interfaces are not online yet.

In the meantime, you can try disabling the RigVM.BlueprintIndependentAssets cvar. Then new assets would work.

Dustin

[Attachment Removed]

Hello Dustin,

We finally had time to test this; here are our findings.

The compiled node works, BUT ONLY when spawning a rig as absolute not as an additive rig. If you run the node with the IsLayered flag enabled while spawning a Modular Rig (as a Control Rig Runtime Asset type) it returns this error:

LogTemp: Error: Cannot add an additive control rig which does not contain a backwards solve event

We suspect this has not something to do with the script but with the Modular Rigs themselves.

To test this we built a Modular Rig for Quinn using modules from the Control Rig Starter Content and tried to assign it to a Skeletal mesh in the Sequencer using the default UI. The result was the same. We received the same error and the Control Rig failed to spawn.

To get around this, the rig must be created as a normal rig and then the Layered Flag needs to be toggled manually in the UI.

We think this indicates a further bug, specifically relating to Modular Rigs in Layered mode, where it is failing to detect a backsolve graph upon creation.

Could you please look into this and let us know if this is the case or if there is something potentially interfering on our side?

Futhermore…while a Modular Rig fails completely to spawn with IsLayered enabled when typed Control Rig Runtime Asset if we spawned it as a Control Rig Blueprint type the rig will be created but after a really longhangtime (1min 30 sec circa).

We are putting a separate ticket for these hangtimes. [Content removed]

We believe these two issues to be related.

Please let us know when you have time to investigate this.

Thank you in advance,

[Attachment Removed]

Hey there,

There’s another small code change you can make that would make things easier.

In /ControlRigEditorAsset.cpp, -> IControlRigEditorAssetInterface::RecompileModularRig():

FControlRigAssetStrongReference RigSource = GetControlRigAssetReference();
        if (RigSource.IsModularRig())
        {
                PropagateModuleHierarchyFromBPToInstances();
                RequestConstructionOnAllModules();
        }
 
        UpdateModularDependencyDelegates();
 
//Add the below lines.
+       // Module changes can add or remove events (such as Backwards Solve); keep the cached list that
+       // Sequencer's Layered check reads in sync instead of waiting for the next save.
+       GetRigVMAssetInterface()->UpdateSupportedEventNames();
+
 #if WITH_EDITOR
        if(GetObjectBeingDebugged() == nullptr)
        {
                GetRigVMAssetInterface()->SetObjectBeingDebugged(CreateControlRig());
        }
 #endif

This should help ensure that the modular rig adds when saved pass the checks that error indicates.

Dustin

[Attachment Removed]