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 ...
随机推荐
- mac svn 使用
上传文件 $ svn import file.xls svn://ip/sursen/05I\&V周报 -m "te" 备注: -m "冒号里面一定填写文件 ...
- <raspberry pi > 用树莓派来听落网电台
树莓派放在抽屉里吃灰有半年多了,去年玩了1个月后就没怎么开整了,上个月没工作,刚好有点闲暇,就把树莓派翻出来折腾,刚好碰到落网改版了,想起以前在树莓派论坛看到有网友拿树莓派来听豆瓣电台,代码那时我都下 ...
- java和js互调 webview
public class JavaAndJSActivity extends Activity implements View.OnClickListener { private EditText e ...
- FZU1989 AntiAC —— 字符串
题目链接:https://vjudge.net/problem/FZU-1989 Problem 1989 AntiAC Accept: 79 Submit: 399Time Limit: 4 ...
- 轻量级RPC框架开发
nio和传统io之间工作机制的差别 自定义rpc框架的设计思路 rpc框架的代码运行流程 第2天 轻量级RPC框架开发 今天内容安排: 1.掌握RPC原理 2.掌握nio操作 3.掌握netty简单的 ...
- html5--2.1新的布局元素(1)-header/footer
html5--2.1新的布局元素(1)-header/footer 学习要点 了解header/footer的语义和用法 使用header/footer进行一个简单的布局 header元素(标签) 用 ...
- SpringBoot_00_资源汇总贴
一.精选 1.Spring Boot文档 二.参考资料 1.springboot-learning-example 2.Spring boot 那些事 3.Spring Boot干货系列 4.Spri ...
- Ajax动态切换按钮
function changeAjax(str, obj) { var idx = $(obj).parent().parent().index(); if(confirm('确定执行操作么?')) ...
- Go丨语言学习笔记--switch
Java语言与Go语言的switch对比 Go语言 switch str { case "yes" : do something ... case "no" d ...
- poj-1986 Distance Queries(lca+ST+dfs)
题目链接: Distance Queries Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 11531 Accepted ...