Hi!
I’ve been writing a volume for my game which is supposed to spawn rocks that are falling on player.
I’ve set up a FTimerDelegate that is bound with spawn function and timer that executes a given delegate after every 3 seconds.
void AStoneEmitterVolume::BeginPlay()
{
Super::BeginPlay();
FVector VolumeLocation = VolumeComponent->GetComponentLocation();
UE_LOG(LogTemp, Warning, TEXT("VolumeLocation: %s"), *VolumeLocation.ToString());
FTimerHandle SpawnTimerHandle;
FTimerDelegate EmitStoneDelegate;
EmitStoneDelegate.BindUFunction(this, FName{ TEXT("SpawnStones") }, &VolumeLocation);
GetWorldTimerManager().SetTimer(SpawnTimerHandle, EmitStoneDelegate, SpawnDelay, true);
}
The line
“UE_LOG(LogTemp, Warning, TEXT(“VolumeLocation: %s”), *VolumeLocation.ToString());”
inputs the exact location of BoxComponent. But wait for it - things will get interesting soon.
void AStoneEmitterVolume::SpawnStones(FVector& Location)
{
if (SpawnableActor)
{
FVector* SpawnLocation = &Location;
UE_LOG(LogTemp, Warning, TEXT("VolumeLocation: %s"), *SpawnLocation->ToString());
UE_LOG(LogTemp, Warning, TEXT("VolumeComponent->GetComponentLocation(): %s"), *VolumeComponent->GetComponentLocation().ToString());
FActorSpawnParameters SpawnInfo;
ABreakableObstacle* SpawnedActor = Cast<ABreakableObstacle>(()->SpawnActor(ABreakableObstacle::StaticClass(), SpawnLocation, &FRotator::ZeroRotator, SpawnInfo));
SpawnedActor->GetRenderComponent()->SetMobility(EComponentMobility::Movable);
SpawnedActor->GetRenderComponent()->SetSimulatePhysics(true);
SpawnedActor->GetRenderComponent()->SetConstraintMode(EDOFMode::XZPlane);
UE_LOG(LogTemp, Warning, TEXT("SpawnedActor exists: %s"), (SpawnedActor) ? TEXT("TRUE") : TEXT("FALSE"));
}
}
So I log the value of the volumecomponent location as vector refence on the line
UE_LOG(LogTemp, Warning, TEXT(“VolumeLocation: %s”), *SpawnLocation->ToString());
and it outputs me a value VolumeLocation: X=4663971676160.000 Y=0.000 Z=-431595552.000
However, when I log the volumecomponent location directly on the line
UE_LOG(LogTemp, Warning, TEXT(“VolumeComponent->GetComponentLocation(): %s”), *VolumeComponent->GetComponentLocation().ToString());
I get the right vector value.
I am not sure what’s causing this weird behavior, I’ve also tried to find answers on the internet, but haven’t found any similar problem yet.
Waiting for your response,
With regards