C++ GetOwner and GetActorEyesViewPoint on a weapon class

Rebel_Camp_Games
Mon, 15 Oct 2018 08:50:39 +0000
Platform & Builds

Hi all!

I got a problem with setting GetActorEyesViewPoint in my SGrenadeLauncher class.

In my SCharacter class I do the following:

if (TheGrenadeLauncherWeapon)
	{
		TheSpawnedWeapon = GetWorld()->SpawnActor<AActor>(TheGrenadeLauncherWeapon, FVector(0), FRotator(0));

		const USkeletalMeshSocket* WeaponSocket = GetMesh()->GetSocketByName("WeaponSocket");
		WeaponSocket->AttachActor(TheSpawnedWeapon, GetMesh());
}

In my SGrenadeLauncher.cpp I do this:

void ASGrenadeLauncher::FireWeapon()
{
	AActor* MyOwner = GetOwner();
	MyOwner->GetActorEyesViewPoint(EyeLocation, EyeRotation); // On this line the editor crashes
}

So the editor crashes on GetActorEyesViewPoint of MyOwner. So something is wrong with MyOwner.

I think either the MyOwner does not find the correct SCharacter Actor, or the MyOwner should be a ACharacter or APawn or something for GetActorEyesViewPoint to work.

In SCharacter.cpp I attached the weapon to the socket. So I would think if I do GetOwner in SGrenadeLauncher.cpp that it would return me the SCharacter as an Actor. So any idea why my code doesn’t work?

Thanks in advance!

4 posts - 1 participant