# Spawn new Box Brush in C++

**URL:** <https://forums.unrealengine.com/t/spawn-new-box-brush-in-c/374916>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [October 30, 2016, 10:00pm UTC](https://forums.unrealengine.com/t/spawn-new-box-brush-in-c/374916 "2016-10-30T22:00:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mortmaire](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mortmaire](https://forums.unrealengine.com/u/mortmaire)\
**Post date:** [October 30, 2016, 10:00pm UTC](https://forums.unrealengine.com/t/spawn-new-box-brush-in-c/374916/1 "2016-10-30T22:00:42Z")

</div>

Like a topic name. The best answer would be a function to spawn brushes during the game. I know the answer from:

> **[How to create / spawn boxes with box brush in c++](https://forums.unrealengine.com/questions/100323/how-to-create-spawn-boxes-with-box-brush-in-c.html)**
>
> Hello, is it possible to spawn a box brush using c++? Thanks edit: I found something interesting here: and The latter says that the brushes are not made for realtime creation.

but I am still not convinced. I want to test it myself. Also, one would consider creating complicated objects with brushes in editor (like fractal-like structures), which is obviously not possible without scripting.

---

<div class="post-metadata">

**Author:** ![mortmaire](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mortmaire](https://forums.unrealengine.com/u/mortmaire)\
**Post date:** [October 31, 2016, 1:35am UTC](https://forums.unrealengine.com/t/spawn-new-box-brush-in-c/374916/2 "2016-10-31T01:35:23Z")

</div>

I have found it, and it took me (only) two days. To be honest it’s not that hard, but unnecessary complicated - maybe it will evolve into pull request of source code. Here is the code which I used to spawn new Box Brush:

```
UWorld *World = GEditor->GetEditorWorldContext().World();
ABrush *NewBrush = World->SpawnBrush();
NewBrush->BrushBuilder = NewObject<UBrushBuilder>(NewBrush, UCubeBuilder::StaticClass(), NAME_None, RF_Transactional);
NewBrush->Brush = NewObject<UModel>(NewBrush, NAME_None, RF_Transactional);
NewBrush->Brush->Initialize(NewBrush, false);
NewBrush->BrushType = EBrushType::Brush_Add;
NewBrush->BrushBuilder->Build(NewBrush->GetWorld(), NewBrush);
NewBrush->SetNeedRebuild(NewBrush->GetLevel());
GEditor->RebuildAlteredBSP(); 

```

Honestly, it needs some tutorial or explanation in Documentation. Single SpawnBrush function SHOULD get you complete and usable object, not empty uninitialized actor. Also, SpawnActor function is used only 3 (three!) times in source code, according to GitHub.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_bffaf5b8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_bffaf5b8](https://forums.unrealengine.com/u/anonymous_user_bffaf5b8)\
**Post date:** [November 17, 2016, 6:23am UTC](https://forums.unrealengine.com/t/spawn-new-box-brush-in-c/374916/3 "2016-11-17T06:23:58Z")

</div>

what’s the version of your UE4

---

<div class="post-metadata">

**Author:** ![VincentJun](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VincentJun](https://forums.unrealengine.com/u/VincentJun)\
**Post date:** [December 5, 2016, 11:50am UTC](https://forums.unrealengine.com/t/spawn-new-box-brush-in-c/374916/4 "2016-12-05T11:50:28Z")

</div>

hello, can you spawn a box brush? why did i can’t compile four line UCubeBulider must be a class or namespace name,seven line pointer to incomplete class type is not allowed…please help me …thanks

---

<div class="post-metadata">

**Author:** ![VincentJun](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VincentJun](https://forums.unrealengine.com/u/VincentJun)\
**Post date:** [December 5, 2016, 12:10pm UTC](https://forums.unrealengine.com/t/spawn-new-box-brush-in-c/374916/5 "2016-12-05T12:10:07Z")

</div>

in the end can you solve this problem? if you have a good idea ,can you share for me?

---

<div class="post-metadata">

**Author:** ![ZaruWright](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ZaruWright](https://forums.unrealengine.com/u/ZaruWright)\
**Post date:** [June 18, 2018, 1:13pm UTC](https://forums.unrealengine.com/t/spawn-new-box-brush-in-c/374916/6 "2018-06-18T13:13:07Z")

</div>

You have the answer on the following link [https://answers.unrealengine.com/questions/25346/how-to-use-editor-classes-from-within-an-actor-cla.html](https://answers.unrealengine.com/questions/25346/how-to-use-editor-classes-from-within-an-actor-cla.html).

Basically you have to add the UnrealEd module Into your Build.cs file. You have to have something like this:

PublicDependencyModuleNames.AddRange(new string[] { “Core”, “CoreUObject”, “Engine”, “InputCore”, “UnrealEd” });

And recompile your project again.

---

<div class="post-metadata">

**Author:** ![tangfuling](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tangfuling](https://forums.unrealengine.com/u/tangfuling)\
**Post date:** [September 5, 2020, 11:09am UTC](https://forums.unrealengine.com/t/spawn-new-box-brush-in-c/374916/7 "2020-09-05T11:09:55Z")

</div>

How to change Brush SurfaceMaterial by C++ ？
