I’m attempting to pass a ‘Weapon’ class into my character, spawn it and attach it to my character so it moves with it (I understand this can be done with sockets but do not currently want to do that). The weapon actor gets spawned, but its bellow the floor in my level and does not move at all with the character. I have checked that everything has a mobility of EComponentMobility::Movable.
Weapon is spawned like this (taken from the first person projectile spawning example):
if (CurrentWeapon != NULL)
{
const FRotator SpawnRotation = GetControlRotation();
const FVector SpawnLocation = GetActorLocation() + SpawnRotation.RotateVector(GunOffset);
UWorld* const World = ();
if (World != NULL)
{
SpawnedWep = World->SpawnActor<AWeapon>(CurrentWeapon, SpawnLocation, SpawnRotation);
SpawnedWep->AttachRootComponentToActor(this, NAME_None, EAttachLocation::KeepRelativeOffset);
}
}
This is the Weapons constructor:
GunOffset = FVector(100.0f, 30.0f, 10.0f);
WeaponMesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("WeaponMesh"));
WeaponMesh->SetOnlyOwnerSee(false);
WeaponMesh->SetVisibility(true, true);
WeaponMesh->RelativeLocation = GunOffset;
WeaponMesh->bCastDynamicShadow = true;
WeaponMesh->CastShadow = true;
WeaponMesh->Mobility = EComponentMobility::Movable;
EDIT:
I have even tried setting up a tick to manually move the Weapon. This does not work either. Shown below:
void AProjectAloeCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (SpawnedWep != NULL)
{
UE_LOG(LogTemp, Warning, TEXT("Move being called")); // This is being called
SpawnedWep->SetActorLocation(GetActorLocation());
}
}