Custom Anim Node: Where do I place bone transform code?

Hi guys,

I want to re-create a simple blueprint-based VR IK setup, but written in C++. I’ve been mirroring the Blueprint process in C++, and so far so good. It turns out that I can’t easily type everything out in C++ and have it all run. Instead, it looks like I’ll do most of the heavy lifting in C++ and pass over all of that heavy lifting in the form of a custom Anim Graph Node. However, I don’t understand the structure of the custom Anim Node, which means that I don’t know where to type the IK logic code.

The idea I’m going after is pretty simple. The blueprint-based Simple VR IK works like this:

1) It stores the motion controller transforms in the EventGraph portion of the Anim Instance.

1.a) I mirrored this process by creating my own custom Anim Instance in C

// Fill out your copyright notice in the Description page of Project Settings.


#include "MyVRAnimInstance.h"
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "GameFramework/Actor.h"
#include "VRPawn.h"
#include "Engine/Classes/Animation/AnimInstance.h"
#include "Runtime/HeadMountedDisplay/Public/MotionControllerComponent.h"



UMyVRAnimInstance::UMyVRAnimInstance()
{
	Speed = 0.0;
}

void UMyVRAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
{
	Super::NativeUpdateAnimation(DeltaSeconds);
	AActor* OwningActor = GetOwningActor();
	APawn* PawnOwner = TryGetPawnOwner();
	AVRPawn* myVRpawn;

	


	myVRpawn = Cast<AVRPawn>(PawnOwner);
	
	if(OwningActor != nullptr)
	{
		Speed = OwningActor->GetVelocity().Size();
	}
	if (PawnOwner != nullptr && myVRpawn != nullptr)
	{
		LMotionControllerTransform = myVRpawn->LeftMotionController->GetComponentTransform();
		RMotionControllerTransform = myVRpawn->RightMotionController->GetComponentTransform();

	}
		
}

2) The simple blueprint VR IK example then pulls the Motion Controller transforms within the AnimGraph section of the Anim Instance, and applies FABRIK IK logic to it.

2.a) In an attempt to mirror the process above, I created an empty shell of a custom AnimNode. However, I don’t know where to place the FABRIK logic. Where do I place the FABRIK logic? In which section of my Custom Anim Node? Below i include an image of the Theoretical AnimGraphNode (right now it’s just a shell, but this is how I envision it working). Further below that, I am including my custom Anim Node cpp file.

CUSTOM ANIM GRAPH NODE CPP FILE BELOW
Where do I place the FABRIK functions and how do I return them back out from the node, as in the image above?

// Fill out your copyright notice in the Description page of Project Settings.

#include "MyAnimNode.h"
#include "CoreMinimal.h"
#include "MyVRGame.h"
#include "Animation/AnimInstanceProxy.h"


FMyAnimNode::FMyAnimNode() 
{

}

void FMyAnimNode::Initialize_AnyThread(const FAnimationInitializeContext& Context) 
{
	Super::Initialize_AnyThread(Context);
	
	BasePose.Initialize(Context);
	
}

void FMyAnimNode::CacheBones_AnyThread(const FAnimationCacheBonesContext& Context) 
{
	BasePose.CacheBones(Context);
}

void FMyAnimNode::Update_AnyThread(const FAnimationUpdateContext& Context) 
{
	GetEvaluateGraphExposedInputs().Execute(Context);
	
	BasePose.Update(Context);
}

void FMyAnimNode::Evaluate_AnyThread(FPoseContext& Output) 
{
	// Evaluate the input
	BasePose.Evaluate(Output);
	//Output.Pose.GetBoneContainer().
}

void FMyAnimNode::GatherDebugData(FNodeDebugData& DebugData) {
	FString DebugLine = DebugData.GetNodeName(this);


	DebugData.AddDebugItem(DebugLine);

	BasePose.GatherDebugData(DebugData);
}

Hi! Animation main points in Unreal are

  1. Evaluation Nodes, that are used in AnimInstances and AnimInstanceProxies are here
    https://github.com/EpicGames/UnrealEngine/tree/df84cb430f38ad08ad831f31267d8702b2fefc3e/Engine/Source/Runtime/AnimGraphRuntime/Private/AnimNodes
    They are used as blocks to modify bone pose

  2. Editor Nodes, they are used only to config animation with Unreal Editor in Anim Blueprint and in fact generate Evaluation Nodes.
    https://github.com/EpicGames/UnrealEngine/tree/df84cb430f38ad08ad831f31267d8702b2fefc3e/Engine/Source/Editor/AnimationBlueprintEditor/Private/AnimationNodes

So, animation pipe is roughly

  • Create AnimationBlueprint and create some special graph of Editor Nodes.
  • After that Graph of Editor Nodes compiles to graph of Evaluation Nodes
  • This graph of Evaluation Nodes is used by AnimInstance to animate Skeletal meshes

If your question is where to place bone transform code, simply look at this base class
https://github.com/EpicGames/UnrealEngine/blob/df84cb430f38ad08ad831f31267d8702b2fefc3e/Engine/Source/Runtime/Engine/Classes/Animation/AnimNodeBase.h#L906

Thank you! Yup it looks like I gotta put it in the Evaluate override. As I’ve been reading and looking up more info on this, now, I’m not sure if I should be using AnimNode_Base or AnimNode_SkeletalControlBase… But, one step at a time! Thank you Kehel!