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:
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.
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
CharacterToAttack
is custom type of ATDAICharacter
that extends from ATDCharacter
GetWorldTimerManager().SetTimer()
#include "iTween/iTween.h"
to the top of my TDWeapon.cpp
fileAh, the problem wasn't in the code. I was using "simulate in editor" in the UE4 Editor rather than "play in editor".
It appears that AiTweenEvent* UiTween::SpawnEvent(AiTAux* aux)
needs a player controller and uses GetWorldLocal()->GetFirstPlayerController()->GetPawn()->GetTransform()
to get it's transform. In my instance, "simulate in editor" doesn't spawn a player so GetPawn()
returns nullptr
which GetTransform()
doesn't like.
Awesome.