简体   繁体   English

UE4 iTween C ++抛出“ this is nullptr”

[英]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.hActor.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: 我认为其他信息可能很重要:

  1. actorToRotate is custom type of ATDWeapon that extends from AActor actorToRotate是自定义类型ATDWeapon从延伸AActor
  2. CharacterToAttack is custom type of ATDAICharacter that extends from ATDCharacter CharacterToAttackATDAICharacter自定义类型, ATDAICharacter是从ATDCharacter扩展而来的
  3. The function that executes this code is called by GetWorldTimerManager().SetTimer() 执行此代码的函数由GetWorldTimerManager().SetTimer()调用
  4. I've added #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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM