[Question] How to access variable from a Blueprints Event graph in C++

An example is I have an animation blueprint that has a has torch Boolean variable that blends the characters default walk animation with a idle animation of him holding a torch I’m wondering how I can get access to that variable from c++ code so I can toggle it at run-time… Is this possible? If so what function?

Dear Aidan,

You should create the variable in the c++ instead, by creating your own custom animation blueprint class.

Then you need to re-parent your anim blueprint to use your custom animation blueprint class, and then the variable will appear in the right click menu

I do this all time so I know it will work for you :slight_smile:

here’s the basic code for what you are asking

// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.

#pragma once

#include "VictoryAnimInstance.generated.h"

UCLASS(transient, Blueprintable, hideCategories=AnimInstance, BlueprintType)
class UVictoryAnimInstance : public UAnimInstance
{
	GENERATED_UCLASS_BODY()
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Movement)
	bool UseBackwardsBlendSpace;
	
};

// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.

#include "VictoryGame.h"

//////////////////////////////////////////////////////////////////////////
// UVictoryAnimInstance

UVictoryAnimInstance::UVictoryAnimInstance(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	UseBackwardsBlendSpace = false;
}

I have a tutorial on setting anim blueprint vars from C++ here

http://forums.epicgames.com/threads/972861-Tutorial-Compile-C-for-UE4-Code-Samples-For-You-(New-Create-Material-Instances)?p=31653957&viewfull=1#post31653957

#Reparent That Anim BP

Dont forget to re-parent your anim BP after you compile your new source code!!

picture of this at the link above to my tutorial
Rama

Thanks Rama,

Funny enough my teammate went though your forum post himself and noticed that’s how you were doing it and we have been kinda debating it since. Should work for us but we shall keep you posed :slight_smile:

Aidan

It’s really not compicated, especially if you add a reference to your custom anim class in your character class.

This custom anim reference would get set during Post Init Components

and then you can use that to get/set custom vars from the anim instance very easily

just please

ALWAYS CHECK

that the anim instance var is valid!

:slight_smile:

protected:
	
	//Anim Instance
	UDragonHumanAnimInstance *Animation;


void AVictoryDragonHuman::PostInitializeComponents()
{
	Super::PostInitializeComponents();	
//Retrieve Custom Anim Instance
	Animation = Cast( Mesh->GetAnimInstance() );
	
	//Could not retrieve anim instance?
	if(!Animation) return;

        //Animation->DoStuff()

}