How to reset state machine behind a slot in Anim Blueprint?

Hi,

We have a state machine that feeds directly into a slot in our Anim Blueprint:

19867-statereset.png

(not sure why the no slot name appears, that’s something that has come in 4.5, the slot is actually setup correctly)

The issue we have is that when the slot is active the state machine does not update, then once we are done with our montages the state machine resumes where it left off, causing animation issues. I have seen similar questions posted which recommended using a blend so that the state machine never has a weight of zero and keeps updating. Unfortunately that isn’t good enough for us, I need the state machine to actually reset back to the entry once it becomes active again.

What is the best way of achieving this?

Cheers,

There is no nice way to achieve this. But it can be done with a small code change.

Add a bool to AnimNode_Slot to indicate whether to reset children when they become relevant:

// Whether to reset the children of the slot when they become relevant again
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Settings, meta=(CustomizeProperty))
bool ResetChildren;

Then in the update, save off the source weight before updating it and if it’s now non-zero and was zero and the Boolean is true, then call Initialize on Source prior to calling Update:

void FAnimNode_Slot::Update(const FAnimationUpdateContext& Context)
{
    float ChachedSourceWeight = SourceWeight;

	// Update weights.
	Context.AnimInstance->GetSlotWeight(SlotName, SlotNodeWeight, SourceWeight);

	// Update cache in AnimInstance.
	Context.AnimInstance->UpdateSlotNodeWeight(SlotName, SlotNodeWeight);

	if (SourceWeight > ZERO_ANIMWEIGHT_THRESH)
	{
        if (ChachedSourceWeight <= ZERO_ANIMWEIGHT_THRESH && ResetChildren)
        {
            FAnimationInitializeContext InitContext(Context.AnimInstance);
            Source.Initialize(InitContext);
        }

		Source.Update(Context.FractionalWeight(SourceWeight));
	}
}

This will reset the downstream nodes when they become relevant again (when the slot goes off of full weight).

Now you can set the bool in the Anim Blueprint:

20367-resetchildren.png

You should add a pull request for this small change. There are too few options available in the Animation Blueprint to have control right now. This is a perfect addition that only do good.

Cheers!

I believe that this is not really the correct way for doing this sort of thing because it doesn’t catch everything. To quote what I’ve been warned about:

“this will work for most uses of slots, but isn’t true relevancy, if something much further up in the tree set weight to zero and back you wouldn’t catch it”

It works fine in my case though, which is why I put up the code here for others to use at their own risk.