Download

Edit Animation Blueprint Programatically in C++

Hello, I have quite a specific question about something I’m trying to do that’s been bothering me for the last few days.
It’s been requested by our designers that when duplicating a blueprint, the animations that that blueprint references to be duplicated as well.

To be more specific, we have an actor blueprint that references a Main Animation Blueprint through a SkeletalMeshComponent, that Main Animation Blueprint contains Linked Anim Graph Nodes inside.
I am easily able to duplicate the Main Animation Blueprint and replace it inside the SkeletalMeshCompoent in the new Actor Blueprint but that’s not all that’s required.

What I am wanting to do is get the Animation Blueprints referenced by those nodes, duplicate them then replace the reference in the new Main Animation Blueprint. So that basically gives us a clean, new Main Animation Blueprint with all of the children Animation Blueprints new as well.

Where I am right now is I am able to reliably get the referenced UBlueprintGeneratedClasses referenced in those Linked Anim Graph Nodes from the CDO of the Main Anim Blueprint, then duplicate the AnimationBlueprint of those classes.
From here on the problem arises, no matter how I tried to replace the reference in the existing FAnimNode_LinkedAnimGraph type structs inside that CDO, nothing is represented in the editor. The new AnimationBlueprint still references the old Anim Blueprint children, even though the new ones are created and the InstanceClass theoretically replaced in the code.

From what I am able to see, no Animation Blueprint editing is done in the editor without an AnimInstance being present, which basically requires either a preview of the animation to be shown or the game to be running with an instance in it.
I am aking if anyone has managed to do something similar to this or if they know of anything that would allow to edit the Animation Blueprints in this way.

Have actually figured this out.
It seems in a blueprint there are two places where the data is kept, the graph and the class default object. The graph is the source of truth and the class default object gets created from it at compile time.
So what I had to do was go through the Blueprint’s FunctionGraphs member, then through the nodes and at the end edit the actual F nodes inside the AnimGraph nodes.
The compiler takes care of the rest.