Expose FBoneReference to Blueprint

I am in a research team trying to develop an full body motion virtual reality using a Phase Space + Oculust Rift setup.

We’ve been using Unity for the past year as our game engine and I’m trying to migrate to UE4. I already figured out all the piece I needs to achieve what I want : in simple words I have a SkeletalMesh with Sockets that I need to move around using IK Two Bone, FABRIK and Transform Bone in the Anim Graph to match my mocap data at run time.

The only thing that I can not find is how to expose to Blueprint the FAnimNode_ModifyBone::BoneToModify, FAnimNode_Fabrik::TipBone and FAnimNode_Fabrik::RootBone. I tried to mess around with their UPROPERTY tag with no luck, still not showing as a Pin in the graph and that’s what I need to accomplish my migration.

Can anyone explain/give me direction on how could I expose the Pin for these 3 FBoneReference in the Blueprint system?

Attached is a small screen of my debug mocap data that I’m trying to map to my SkeletalMesh in UE4.

Welcome to the forums Gern!

:slight_smile:

A Solution

The core of a BoneReference is really just the FName


USTRUCT()
struct FBoneReference
{
	GENERATED_USTRUCT_BODY()

	/** Name of bone to control. This is the main bone chain to modify from. **/
	UPROPERTY(EditAnywhere, Category=BoneReference)
	FName BoneName;

	/** Cached bone index for run time - right now bone index of skeleton **/
	int32 BoneIndex;

	FBoneReference()
		: BoneIndex(INDEX_NONE)
	{
	}

        **//see AnimationAsset.h**


  1. you can make a UPROPERTY FName that is easily exposed to the blueprint node.

//AnimNode_Fabrik.h


UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=BoneNames)
FName TipBoneName;

  1. There is a default constructor, so you can make a new BoneReference,

  2. then assign the bone name from the UPROPERTY FName,

  3. then initialize the bone reference using the required bones you get access to inside the FABRIK .cpp


bool FBoneReference::Initialize(const FBoneContainer & RequiredBones)
{
BoneName = *BoneName.ToString().Trim().TrimTrailing();
BoneIndex = RequiredBones.GetPoseBoneIndexForBoneName(BoneName);

Fortunately you can cache this created BoneReference and only create it once, inside of the FABRIK node .cpp when it is initializing.

//AnimNode_Fabrik.cpp, at the bottom


//use the required bones here to initialize your FName BoneReference!
void FAnimNode_Fabrik::InitializeBoneReferences(const FBoneContainer & **RequiredBones**) 
{
	TipBone.Initialize(RequiredBones);
	RootBone.Initialize(RequiredBones);
	EffectorTransformBone.Initialize(RequiredBones);
}

then you have the fully constructed bone reference, assignable via BP using FName :slight_smile:


The Community Member and author of the FABRIK node might respond to you here, if he doesnt and you still can't figure it out let me know and I can post a more complete code sample

Rama

Thank you Rama, it worked !

I ended up changing the TipBone.BoneName just before the InitializeBoneReferences since changing the BoneName in the constructor seems to do nothing


FAnimNode_Fabrik::FAnimNode_Fabrik()
	: EffectorTransform(FTransform::Identity)
	, EffectorTransformSpace(BCS_ComponentSpace)
	, EffectorRotationSource(BRS_KeepLocalSpaceRotation)
	, Precision(1.f)
	, MaxIterations(10)
	, bEnableDebugDraw(false)
{
	/* This didn't work */
	//TipBone.BoneName = TipBoneName;
	//RootBone.BoneName = RootBoneName;
	//EffectorTransformBone.BoneName = EffectorTransformBoneName;
}

void FAnimNode_Fabrik::InitializeBoneReferences(const FBoneContainer & RequiredBones) 
{
	/* This did work */
	TipBone.BoneName = TipBoneName;
	RootBone.BoneName = RootBoneName;
	EffectorTransformBone.BoneName = EffectorTransformBoneName;

	TipBone.Initialize(RequiredBones);
	RootBone.Initialize(RequiredBones);
	EffectorTransformBone.Initialize(RequiredBones);
}

@Gern, sorry for the off topic request, but you wouldn’t happen to have a brief overview of how to use FABRIK, would you? I wasn’t able to really find any information about it.

For future reference, BP values that you set in UPROPERTY() are never valid until AFTER the class constructor

so for any class, post init or beginplay is the time to start relying on values that are set in the editor for UPROPERTY :slight_smile:

oooh very nice! yea that’s what I had in mind!

I am going to copy this code now hee hee , for when I need to do this with FABRIK :slight_smile:

Great to have you in the Community Gern!

:slight_smile:

Rama

Make sense, thank you for the clarification.

I haven’t played with the FABRIK component for now, I only used the FAnimNode_ModifyBone “Transform (Modify) Bone” as of now. I’ll keep you posted when I get my hand on with UE4’s FABRIK component.

Can anyone please provide some more information about this, because I want to achieve the same thing, getting real-time mocap data from a phasespace impulse X2 system into UE4, but I don’t know where to start. Or is there some semi-plug&play solution already that someone could share with like step by step instructions?