Spawning Actors/Pawns At Runtime On Ground

Hello everyone!

I’m trying to do something pretty simple but I’m running into some problems. I’m making an RTS style base building game. When I start my game, the game mode spawns the default building for each player, and a default unit. The issue I’m having is spawning them correctly on the surface of the ground.

The ‘origin’ (or whatever its called) of my building seems to be the center of the mesh, I would simply move the mesh but subclasses of the building class can specify two meshes in the property window and it dynamically changes between them.

Also the origin of the unit seems to be in the center of the capsule component as well, which I cant move.

So as a result, when I do a trace towards the ground to find a spawn spot for both unit and building, the building spawns half in the ground and the unit wont spawn at all because of collision.

I noticed in the editor when I place those classes into a level, they are ‘half in the ground’ until I release the mouse button in which they perfectly snap to the surface of the ground. I am trying to find how that’s implemented or another way to do it. Any help would be greatly appreciated!

Just to note, for the Pawn I’m trying to spawn, I tried getting a pointer to the CDO and calling GetActorBounds and GetComponentBounds but both of those return a Z value of 0.f for some reason. But, I managed to get the Building (Actor) to work using this method.

You can get a characters capsule half height and add it to your Z component of the spawn, maybe add just acouple of units for clearance too.