SpawnActor does not Spawn accurately

hi everyone, a weird problem. i am trying to spawn an Actor to the scene and it works fine except the spawning part (:
i spawned two other Actors to the scene and they are Spawning accurately. let me give a better view.
i have a Floor Class which Spawns by some rules in the world. now i want to spawn some coins when i spawn floor.
so i decided to code it like this. here is some codes of the Floor.h::

	UPROPERTY(EditAnywhere, Category = "Floor Blueprint")
	TSubclassOf<AFloor> FloorBP = NULL;


	UPROPERTY(EditAnywhere, Category = "CoinBP")
	TSubclassOf<class ACoin> CoinBP = NULL;

and here is some of the key parts of Floor.cpp which when floor Spawns i want to spawn the coins.

void AFloor::OnOverlapBegin(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{

	if (OtherActor && (OtherActor != this) && OtherComp)
	{
		//PlayerPassedFloor.Broadcast();

		SpawnFloorAtLocation.X = this->GetActorLocation().X;
		SpawnFloorAtLocation.Y = this->GetActorLocation().Y;
		SpawnFloorAtLocation.Z = this->GetActorLocation().Z;
		SpawnFloorAtLocation.X += (BoxCompEndOverlap->GetComponentLocation().X - BoxCompStartOverlap->GetComponentLocation().X) + FloorDistance;
		
		//UE_LOG(LogTemp, Error, TEXT("%f"), a) 
		SpawnFloorWithRotation = FRotator(0.f, 0.f, 0.f);
		
		//Spawn new Floor at the end of other floor.
		auto NewFloor = GetWorld()->SpawnActor<AFloor>(FloorBP, SpawnFloorAtLocation, SpawnFloorWithRotation);

		//when ever floor get spawned, coins should be spawn too
		if (CoinBP) {
			if (GetWorld()) {
				GetWorld()->SpawnActor<ACoin>(CoinBP, FVector(0.f, 0.f, 1000.f), SpawnFloorWithRotation);
				UE_LOG(LogTemp, Error, TEXT("COIN COIN COIN"))
			}
		}
	}
}

everything works fine even that UE_LOG below the GetWorld()->SpawnActor(CoinBP, FVector(0.f, 0.f, 1000.f), SpawnFloorWithRotation); works but why on earth nothing Spawns to the scene?
thank you x_X

277807-coincoin.png

Just as a sanity check, can you run in “Selected Editor” and then check the object list on the right side of the editor to check if the coins are actually in the scene or not? If they do appear in that scene list then double check that the positions are right too (In case they can’t spawn at your desired location due to collision and are being placed elsewhere)

GetWorld()->SpawnActor(CoinBP, FVector(0.f, 0.f, 1000.f), SpawnFloorWithRotation);

Spawns a coin at (0.f, 0.f, 1000.f) it’s not relative to the spawn before probably want to spawn it like that

GetWorld()->SpawnActor<ACoin>(CoinBP, SpawnFloorAtLocation + FVector(0.f, 0.f, 1000.f), SpawnFloorWithRotation);

hi and thanks for answering, yeah its not a correct place to spawn coins in real game it was just for testing, it never spawned at (0.f, 0.f, 1000.f)

Your syntax seems funny. Here is one of functions i use for my actor spawning.

Some suggestions for your code would be,

  1. Debug if actor reference is actually created at all. Better than a null check.

    ACoin* ref = GetWorld()->SpawnActor<ACoin>(CoinBP.StaticClass(), FVector(0.f, 0.f, 1000.f), SpawnFloorWithRotation);

    UE_LOG(LogTemp, Warning, TEXT("Mem Address = %d"), ref);

  2. You can declare the rotation inline. No need for extra variables. Same goes for location.