[英]UE4 iTween C++ throws “this was nullptr”
I'm trying to use iTween (via C++, not BP) to rotate an actor to face another, but it throwing an exception in Actor.h
that says: 我正在尝试使用iTween(通过C ++,而不是BP)来旋转一个actor以面对另一个actor,但是它在
Actor.h
中Actor.h
了一个异常,该异常表示:
I'm using the following code to start the tween: 我正在使用以下代码启动补间:
AActor* actorToRotate = Cast<AActor>(this);
if (actorToRotate != nullptr && CharacterToAttack != nullptr)
{
FRotator rotationFrom = actorToRotate->GetActorRotation();
FRotator rotationTo = CharacterToAttack->GetActorRotation();
FName tweenName = TEXT("turret");
AiTweenEvent* TurretTween = UiTween::ActorRotateFromToSimple(tweenName, actorToRotate, rotationFrom, rotationTo, CoordinateSpace::world, false, 2.0f, easeInAndOutQuartic);
}
Rather than using the actorToRotate
variable I've tried using this
in ActorRotateFromToSimple()
but I get the same error. 我没有使用
actorToRotate
变量,而是尝试在ActorRotateFromToSimple()
使用this
变量,但是却遇到了相同的错误。
if (CharacterToAttack != nullptr)
{
FRotator rotationFrom = GetActorRotation();
FRotator rotationTo = CharacterToAttack->GetActorRotation();
FName tweenName = TEXT("turret");
AiTweenEvent* TurretTween = UiTween::ActorRotateFromToSimple(tweenName, this, rotationFrom, rotationTo, CoordinateSpace::world, false, 2.0f, easeInAndOutQuartic);
}
If anyone smarter than me shed some light onto this issue it would be greatly appreciated. 如果有比我聪明的人对这个问题有所了解,将不胜感激。
Additional information I think might be important: 我认为其他信息可能很重要:
actorToRotate
is custom type of ATDWeapon
that extends from AActor
actorToRotate
是自定义类型ATDWeapon
从延伸AActor
CharacterToAttack
is custom type of ATDAICharacter
that extends from ATDCharacter
CharacterToAttack
是ATDAICharacter
自定义类型, ATDAICharacter
是从ATDCharacter
扩展而来的 GetWorldTimerManager().SetTimer()
GetWorldTimerManager().SetTimer()
调用 #include "iTween/iTween.h"
to the top of my TDWeapon.cpp
file TDWeapon.cpp
文件顶部添加#include "iTween/iTween.h"
Ah, the problem wasn't in the code. 嗯,问题不在代码中。 I was using "simulate in editor" in the UE4 Editor rather than "play in editor".
我在UE4编辑器中使用的是“在编辑器中模拟”,而不是“在编辑器中播放”。
It appears that AiTweenEvent* UiTween::SpawnEvent(AiTAux* aux)
needs a player controller and uses GetWorldLocal()->GetFirstPlayerController()->GetPawn()->GetTransform()
to get it's transform. 看来
AiTweenEvent* UiTween::SpawnEvent(AiTAux* aux)
需要一个播放器控制器,并使用GetWorldLocal()->GetFirstPlayerController()->GetPawn()->GetTransform()
进行转换。 In my instance, "simulate in editor" doesn't spawn a player so GetPawn()
returns nullptr
which GetTransform()
doesn't like. 在我的实例中,“在编辑器中模拟”不会产生播放器,因此
GetPawn()
返回nullptr
,而GetTransform()
不喜欢它。
Awesome. 太棒了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.