Spawn Actor Bug

Hello everyone,

I have a simple Puzzle Game.

It is a combination of multiple simple games. Since those games are rotated during the game, everything is spawned dynamically.
I have a problem with SpawnActor.

There is a class called XGame(AActor) spawned by level manager(APawn) . It is responsible for spawning actors for this specific X game.

XGame.cpp



const FVector ActorLocation = GetActorLocation();

const FVector StickLocation = FVector(0, 0, 0) + ActorLocation;
const FVector BallLocation = FVector(0, 100, 0) + ActorLocation;
const FVector CircleLocation = FVector(0, 200, 0) + ActorLocation;

UWorld* World = GetWorld();

AXStick* Stick = World->SpawnActor<AXStick>(StickLocation, FRotator(0, 0, 0));
AXBall* Ball = World->SpawnActor<AXBall>(BallLocation, FRotator(0, 0, 0));
AXCircle* Ball = World->SpawnActor<AXCircle>(CircleLocation, FRotator(0, 0, 0));


The problem is, everytime I spawn an actor its X coordinate is increased by 68. (I don’t know why 68)
For instance;
stick is spawned at 0, 0, 0
ball is spawned at 68, 100, 0
circle is spawned at 136, 200, 0
all of them are ACharacter

I would be really appreciated if anyone can help

Spawn collison behavior defaults to try to adjust the location to resolve collision. You can override it to always spawn and ignore collisions.

I’ve never spawned an actor in my game, using your simple way, I always send the UClass* pointer, i.e.

FActorSpawnParameters SpawnInfo;
SpawnInfo.Owner = this;
SpawnInfo.Instigator = GetInstigator();

AXStick* Stick = World->SpawnActor<AXStick>(AXStick::StaticClass(), StickLocation, FRotator(0, 0, 0), SpawnInfo);

SpawnInfo is optional. It can be omitted.

By the way, I always check if World is not null, i.e.

if (World)
{
// spawn actor
}

I also check that the actual SpawnActor<>() returned a valid pointer, i.e.

if (Stick)
{
}

Good luck!