Custom Component, Unreal Engine里定制组件
来源:互联网 发布:r语言入门 知乎 编辑:程序博客网 时间:2024/06/06 02:28
if you want to do every tick to any Actor, you'd better write your own Component.
the probable problemsyou may went through:
1. TickComponent not called at all.
solution: You can set the ticking properties of a component through its PrimaryComponentTick property. Try adding the following to your component's constructor:
PrimaryComponentTick.bCanEverTick = true;
2. TickComponent called only Once.
Solution: As it turns out. C++ components are not active by default. Activating the component caused TickComponent to be called more than once. Tye adding the following to your component's constructor:
bAutoActivate = true;
3. You can not fine your custom Component in the Add Components List
I think you may be missing sth like "..,meta = (BlueprintSpawnableComponent)" just before function declaration.
Get ActorLocation and Rotation should be written as:
this->GetOwner()->GetLocation();
this->GetOwner()->SetLocation(...);
this->GetOwner()->GetRotation();
this->GetOwner()->SetRotation(...);
Sample:
.h
#pragma once #include "FaceToMainCharacterComp.generated.h" UCLASS(ClassGroup = FaceTo,meta = (BlueprintSpawnableComponent)) class UFaceToMainCharacterComp : public UActorComponent { GENERATED_UCLASS_BODY() protected: virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction); };
.cpp
#include "MyThirdPersonCode.h" //change it to YourOwnGame.h#include "FaceToMainCharacterComp.h"UFaceToMainCharacterComp::UFaceToMainCharacterComp(class FPostConstructInitializeProperties const &PCIP): Super(PCIP){PrimaryComponentTick.bCanEverTick = true;bAutoActivate = true;}void UFaceToMainCharacterComp::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction){Super::TickComponent(DeltaTime, TickType, ThisTickFunction);ACharacter* player = UGameplayStatics::GetPlayerCharacter(this, 0);FVector playerLoc = player->K2_GetActorLocation();FVector actorLoc = this->GetOwner()->GetActorLocation();FVector offDir = playerLoc - actorLoc;offDir *= FVector(1.0, 1.0, 0.0);offDir.Normalize();FRotator rot = offDir.Rotation();this->GetOwner()->SetActorRotation(rot);FVector tmp;float length = 0.0;FVector distDir = playerLoc - actorLoc;distDir.ToDirectionAndLength(tmp, length);distDir.Normalize();if (length > 100.0){ this->GetOwner()->SetActorLocation(actorLoc + distDir);}}
0 0
- Custom Component, Unreal Engine里定制组件
- Custom Depth in Unreal Engine 4
- Unreal Engine 4 C++ Component介绍——BrainComponent
- Unreal Engine 4 C++ Component介绍——WidgetComponent
- unreal component
- Unreal Engine 2
- Unreal Engine 2X
- Unreal Engine 3
- unreal Engine总结
- Unreal Engine 4 发布
- Unreal Engine 4 Terminology
- Unreal Engine API Reference
- UNREAL ENGINE 4.12 RELEASED!
- unreal engine timeline function
- Android 用户界面---定制组件(Custom Components)(一)
- Android 用户界面---定制组件(Custom Components)(二)
- biztalk定制管道组件(pipeline component)的调试、部署
- biztalk定制管道组件(pipeline component)的开发
- 协程介绍
- Oracle数据库备份数据缺失的问题
- 【HDU】4862 Jump 费用流
- perf usage
- yarn学习心得 yarn上的程序开发
- Custom Component, Unreal Engine里定制组件
- UVa10978 - Let's Play Magic!(扑克类的游戏)
- 例子使用
- 字符串String 池
- CSS透明opacity和IE各版本透明度滤镜filter的最准确用法
- uC/OS-II 学习笔记:任务创建步骤
- 第一天-Java语言简介,环境搭建等
- 学拳录 24中盘 (07.29更新)
- 编程之美,3.11程序改错, 二分扩展