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 ...
随机推荐
- Java for LeetCode 131 Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- Android 破解
一.反编译 默认你的电脑中完好的有java环境 1.下载 Android killer 链接: https://pan.baidu.com/s/1s6lfm8CbdU9ABYEOhdFWxA 提取码 ...
- 从mediaserver入手快速理解binder机制(最简单理解binder)【转】
本文转载自;https://blog.csdn.net/u010164190/article/details/53015194 Android的binder机制提供一种进程间通信的方法,使一个进程可以 ...
- smokeping 报警配置
摘自: http://blog.csdn.net/achejq/article/details/51556494 smokeping 默认用sendmail 发邮件告警,也可以直接调用外部程序进行报警 ...
- ThinkPHP基础(1)
多层MVC模式 M:Model 数据模型层,负责数据操作 V:View 视图层,负责显示视图 C:Controller 控制器,实现业务逻辑 控制器访问及路由解析 通过url地址get参数找到指定的控 ...
- PHP5.3之后的新特性【转】
http://blog.csdn.net/black_ox/article/details/21163193
- CI公用模型
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * SEO管理系统 -- 公用模型 ...
- Speaking 1
What clothes do you usually like to wear?Well I like fashionable clothes, but I also want to be comf ...
- Meta viewport 学习整理
The meta viewport tag contains instructions to the browser in the matter of viewports and zooming. I ...
- Qt之log数据展示模块简要实现
Log模块主要用于实时测井数据的显示和测后曲线数据的预览和打印,为更好的展示对Qt中相关知识点的应用,特以Log模块为例对其进行简要实现. 内容导图: 一.功能需求 1.界面效果图 Log模块实现曲线 ...