Animation Blueprint, Set Custom Variables Via C++
https://wiki.unrealengine.com/Animation_Blueprint,_Set_Custom_Variables_Via_C%2B%2B
Animation Blueprint, Set Custom Variables Via C++
Contents
[hide]
Overview
Dear Community,
Here's the basic code you need to control the variables of your AnimBluePrint via c++ code. This is very useful if you just want to use the animblueprint for the actual skeletal
controllers or other nodes of interest to you, but you want to do all the calculations of what their values should be each tick via code. My example is a foot placement system!
It's much easier for me to do traces and get normals and account for various foot size offsets and max limb stretching etc via C++, so I wanted to set the Anim BP vars from
code.
Extending AnimInstance
During Game Time an AnimInstance is created based on your AnimBlueprint, and it is this class that you want to extend to include your variables so you can easily edit them in C++
and get their values in the AnimBluePrint in the Editor.
Here's my code that I am using for my footplacement system:
YourAnimInstance .h
Here's an example of the kind of header you'd use for your extended AnimInstance class. Make sure to change the #include to your exact name! Also make sure to include some extra
spaces at the end of the .h and .cpp file so Visual Studio compiler is happy.
// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved. #pragma once #include "YourAnimInstance.generated.h" UCLASS(transient, Blueprintable, hideCategories=AnimInstance, BlueprintType)
class UYourAnimInstance : public UAnimInstance
{
GENERATED_UCLASS_BODY() /** Left Lower Leg Offset From Ground, Set in Character.cpp Tick */
UPROPERTY(EditAnywhere,BlueprintReadWrite,Category=FootPlacement)
FVector SkelControl_LeftLowerLegPos; /** Left Foot Rotation, Set in Character.cpp Tick */
UPROPERTY(EditAnywhere,BlueprintReadWrite,Category=FootPlacement)
FRotator SkelControl_LeftFootRotation; /** Left Upper Leg Offset, Set in Character.cpp Tick */
UPROPERTY(EditAnywhere,BlueprintReadWrite,Category=FootPlacement)
FVector SkelControl_LeftUpperLegPos;
};
YourAnimInstance .cpp
// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved. #include "YourGame.h" //////////////////////////////////////////////////////////////////////////
// UYourAnimInstance UYourAnimInstance::UYourAnimInstance(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
//set any default values for your variables here
SkelControl_LeftUpperLegPos = FVector(0, 0, 0);
}
Reparent Your AnimBluePrint
Now that you've added new variables you need to compile your C++ code to create your extended AnimInstance, and then load the editor and reparent your current AnimBluePrint to your
subclass:
Once you do this, you can now access your variables from your .h file, and their tooltip in the context menu will be your comment that you set in code!

Connect your custom variables to your anim node chain
The variables can be accessed via the right click menu now!

Accessing Anim Instance in C++
Animation Blueprints are still blueprints,
you must access the instance of the blueprint per-Character.
This is the Animation Instance!
if(!Mesh) return;
//~~~~~~~~~~~~~~~ UYourAnimInstance * Animation =
Cast<UYourAnimInstance>( Mesh->GetAnimInstance() );
if(!Animation) return; Animation->YourInt32Var = 1200;
In-Depth Code Sample
Here's an example of accessing the Anim Instance from the Character class, which is where I am doing it for my foot placement system to easily access socket locations and rotations
etc.
Example Uses In C++ Code Character.cpp
//Never assume the mesh or anim instance was acquired, always check,
//or you can crash your game to desktop void AYourGameCharacter::ResetFootPlacement()
{
//No Mesh?
if (!Mesh) return; UYourAnimInstance * Animation =
Cast<UYourAnimInstance>( Mesh->GetAnimInstance() ); //No Anim Instance Acquired?
if(!Animation) return; //~~ Animation->SkelControl_LeftLowerLegPos = FVector(0,0,0);
Animation->SkelControl_LeftUpperLegPos = FVector(0,0,0);
Animation->SkelControl_LeftFootRotation = FRotator(0,0,0);
} void AYourGameCharacter::DoLeftFootAngleAdjustment(FRotator& FootRot)
{
//No Mesh?
if (!Mesh) return; UYourAnimInstance * Animation =
Cast<UYourAnimInstance>( Mesh->GetAnimInstance() ); //No Anim Instance Acquired?
if (!Animation) return; // //Set Animblueprint node rot
Animation->SkelControl_LeftFootRotation = FootRot;
}
Animation Blueprint, Set Custom Variables Via C++的更多相关文章
- piwik custom variables
piwik custom variables 是一个功能非常强大的自定义变量跟踪方案,多用于基于访客或是页面级别的变量跟踪.piwik默认最多可以添加5个自定义变量. 使用方式是在客户端脚本里添加如 ...
- UE4]不使用角色蓝图、动画蓝图、状态机,用“24K纯C++”实现动画播放
http://aigo.iteye.com/blog/2283454 原文作者:@玄冬Wong 不好意思,我稍稍标题党了,目前还不清楚如何用C++代码来实现BlendSpace和Montage的逻辑, ...
- [UE4] Adding a custom shading model
转自:https://blog.felixkate.net/2016/05/22/adding-a-custom-shading-model-1/ This was written in Februa ...
- 《Note --- Unreal 4 --- behavior tree》
Web: https://docs.unrealengine.com/latest/INT/Engine/AI/BehaviorTrees/index.html Test project: D:\En ...
- 从Unity引擎过度到Unreal4引擎(最终版)
原文地址:http://demo.netfoucs.com/u011707076/article/details/44036839 前言 寒假回家到现在已经有十多天了,这些天回家不是睡就是吃....哎 ...
- Creating and using a blendspace in c++
转自:https://forums.unrealengine.com/development-discussion/c-gameplay-programming/104831-creating-and ...
- [Java in NetBeans] Lesson 04. Class / Objects
这个课程的参考视频和图片来自youtube. 主要学到的知识点有: Class: Blueprint for an object. (e.g. dog is a class) Object: cust ...
- Web开发框架DevExtreme发布v18.2.5|附下载
DevExtreme Complete Subscription是性能最优的 HTML5,CSS 和 JavaScript 移动.Web开发框架,可以直接在Visual Studio集成开发环境,构建 ...
- [UE4]C++设置AnimInstance的相关问题
注意:ue4 4.17调用LoadObject<UAnimBlueprintGeneratedClass>直接崩 http://aigo.iteye.com/blog/2285001 UA ...
随机推荐
- Django创建项目及app
主要环境为python3.5,编译环境为pycharm 首先已经安装好Django相关的组件 1.首先创建Django程序: windows系统下pycharm创建步骤: File->New P ...
- High Performance Browser Networking
Chapter 1. Primer on Latency and Bandwidth As a result, to improve performance of our applications, ...
- 9patch图片
9patch图片可直接缩放,放在drawable文件夹下就可以 右边和下边指定内容区域
- 使用log4j将不同级别的日志信息输出到不同的文件中
使用log4j.xml xml格式的配置文件可以使用filter. 例如想只把log4j的debug信息输出到debug.log.error信息输出到error.log,info信息输出到info.l ...
- 算法(Algorithms)第4版 练习 1.3.23 1.3.22
1.3.23 When it comes time to update t.next, x.next is no longer the original node following x, but i ...
- eclipse如何在不联网的情况下引入dtd约束文件
1. 获取dtd文件,解压 F:\Java配置文件\Mybatis\mybatis-3.3.0\mybatis-3.3.0.jar\org\apache\ibatis\builder\xml\ 路径下 ...
- Linux_学习_02_ 重启tomcat与查看tomcat日志
一.重启tomcat服务器 cd /home/ehlhec/tomcat_dingtalk/bin ./shutdown.sh ps -ef|grep java ./startup.sh (1) 进入 ...
- codeforces 659F F. Polycarp and Hay(并查集+bfs)
题目链接: F. Polycarp and Hay time limit per test 4 seconds memory limit per test 512 megabytes input st ...
- bjwc Day1 暴力大战
今天终于有题了... 题目是COCI2016/2017 Round #4 T1一看就是NP问题,k<=50,开始想暴力,想了个n^4的,大概能过,就没去管它 T2想得太naive,丢了100分给 ...
- poj1456 Supermarket[另类的并查集做法]
1.Supermarket(题目地址) 跟很久以前模拟的打地鼠那题一样,贪心+优先队列.这次换用并查集做法. 还是基于贪心,但这次换一种策略,先选价值最大的, 同时使其尽可能晚的被选上(因为早选会将之 ...