# Spawning Built-in Cube in C++

**URL:** <https://forums.unrealengine.com/t/spawning-built-in-cube-in-c/472754>\
**Category:** Blueprint\
**Tags:** spawn, unreal-engine, cube, question\
**Created:** [October 11, 2020, 1:02pm UTC](https://forums.unrealengine.com/t/spawning-built-in-cube-in-c/472754 "2020-10-11T13:02:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GarenWyvern](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GarenWyvern](https://forums.unrealengine.com/u/GarenWyvern)\
**Post date:** [October 11, 2020, 1:02pm UTC](https://forums.unrealengine.com/t/spawning-built-in-cube-in-c/472754/1 "2020-10-11T13:02:15Z")

</div>

I know versions of this question have been asked before, but either they do not cover my use case or (the more probable case) they do but I just do not understand UE4 enough to see what is happening. I have an actor class that I want to use to spawn in a number of cubes as the level loads (before the gameplay starts). These cubes will be used as obstacles, so I just need to spawn them in particular locations and leave them; no custom functionality is needed. I see that UE4’s editor has a built-in cube mesh under “Basic”, which looks perfect for my needs.

Is it possible to get at this built-in cube and spawn a number of them? I know of `UWorld::SpawnActor`, but that requires a class that I do not know (as far as I can tell, `ACube` is not a thing).

---

<div class="post-metadata">

**Author:** ![GarenWyvern](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GarenWyvern](https://forums.unrealengine.com/u/GarenWyvern)\
**Post date:** [October 15, 2020, 7:05pm UTC](https://forums.unrealengine.com/t/spawning-built-in-cube-in-c/472754/2 "2020-10-15T19:05:53Z")

</div>

I was able to accomplish this by using the following code inside the constructor of an Actor class (i.e. ACube):

```
// Create a static mesh component
UStaticMeshComponent* cubeMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Cube"));

// Load the Cube mesh
UStaticMesh* cubeMesh = ConstructorHelpers::FObjectFinder<UStaticMesh>(TEXT("StaticMesh'/Engine/BasicShapes/Cube.Cube'")).Object;

// Set the component's mesh
cubeMeshComponent->SetStaticMesh(cubeMesh);

// Set as root component
RootComponent = cubeMeshComponent;

```

Once you have the mesh component, you can use `SetWorldScale3D` to reshape it if you want something other than a perfect cube.
