# How can I set the Size of a Mesh using code?

**URL:** <https://forums.unrealengine.com/t/how-can-i-set-the-size-of-a-mesh-using-code/282751>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [May 7, 2014, 5:52pm UTC](https://forums.unrealengine.com/t/how-can-i-set-the-size-of-a-mesh-using-code/282751 "2014-05-07T17:52:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_44db827a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_44db827a](https://forums.unrealengine.com/u/anonymous_user_44db827a)\
**Post date:** [May 7, 2014, 5:52pm UTC](https://forums.unrealengine.com/t/how-can-i-set-the-size-of-a-mesh-using-code/282751/1 "2014-05-07T17:52:26Z")

</div>

Hey! I am having a few problems with setting the size and location of my mesh. For some reason, my Mesh (standard UE4 cube) is a lot bigger than my “collision component”, but I already have all scale related variables set to “0”. In addition, I wanted to ask how I can make the Mesh a child of the “collision component”. Is what I have done okay? Because “collision component” doesn’t have any sockets (its a UBoxComponent).

```
	//Set init values for non-component variables
	RotationRate = 180.f;
	MeshScale = FVector(0.5, 0.5, 0.5);
	MeshLocation = FVector(0, 0, 0);
	MeshRotation = FRotator(0, 0, 0);

	/* Create the mesh component*/
	MeshComp = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("MeshComp"));
	MeshComp->BodyInstance.SetInstanceSimulatePhysics(false);
	MeshComp->bGenerateOverlapEvents = false;
	MeshComp->CastShadow = true;
	MeshComp->bCastDynamicShadow = true;
	MeshComp->AttachTo(CollisionComponent, "");

	//Set init Values for mesh component
	MeshComp->SetRelativeScale3D(MeshScale);
	MeshComp->SetRelativeRotation(MeshRotation);
	MeshComp->SetRelativeLocation(MeshLocation);

```

I also wondered if anyone can tell me why it takes so long for me to update the changes to my mesh. I always have to restart the program etc. which can be pretty frustrating, and even then the program usually doesn’t recognise the changes I made.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_44db827a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_44db827a](https://forums.unrealengine.com/u/anonymous_user_44db827a)\
**Post date:** [May 8, 2014, 7:05am UTC](https://forums.unrealengine.com/t/how-can-i-set-the-size-of-a-mesh-using-code/282751/2 "2014-05-08T07:05:46Z")

</div>

Nobody have any feedback for me?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d1dfbd58](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d1dfbd58](https://forums.unrealengine.com/u/anonymous_user_d1dfbd58)\
**Post date:** [May 8, 2014, 8:54pm UTC](https://forums.unrealengine.com/t/how-can-i-set-the-size-of-a-mesh-using-code/282751/3 "2014-05-08T20:54:12Z")

</div>

I was watching this question and curious what an answer would be, but none yet. I am very new to UE4 and wish I could give you an answer. You mention setting scale values to “0”, but above you use 0.5, do you really want it to not be visible or have 0 volume? Are you not showing the extents of the box component, what did you set that and does it match say the bounds of your box? My apologies if I am way off target. I combed the docs and this codebase is new for me, that’s my disclaimer.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_44db827a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_44db827a](https://forums.unrealengine.com/u/anonymous_user_44db827a)\
**Post date:** [May 8, 2014, 9:04pm UTC](https://forums.unrealengine.com/t/how-can-i-set-the-size-of-a-mesh-using-code/282751/4 "2014-05-08T21:04:43Z")

</div>

No I was just experimenting. I put 0 to see if it did anything, but the box is still bigger than my collision component.

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 9, 2014, 3:30pm UTC](https://forums.unrealengine.com/t/how-can-i-set-the-size-of-a-mesh-using-code/282751/5 "2014-05-09T15:30:10Z")

</div>

#Solution

Make a blueprint of your static mesh actor class

In the editor, go to the components tab

then you can fix everything up very easily

Then you can use C++ to spawn your BP, you can use my templated Spawn BP function to do this!

#Wiki Link

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

#Summary

Manipulating the relationships between components is much easier to do in the editor, especially if you want to visualize what the actual issue is

#Last Step

once you find the solution you could go back to just C++ with greater understanding

Rama

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_44db827a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_44db827a](https://forums.unrealengine.com/u/anonymous_user_44db827a)\
**Post date:** [May 9, 2014, 7:54pm UTC](https://forums.unrealengine.com/t/how-can-i-set-the-size-of-a-mesh-using-code/282751/6 "2014-05-09T19:54:32Z")

</div>

Okay, I found out how to solve the problem. I added the following line (doubt that this was the defining factor):

```
//replaced MeshComp->SetRelativeSacle
MeshComp->SetWorldScale3D(MeshScale);

```

Then I checked in the editor on my blueprint, and the following tab (the “transform” one) appeared, that had not been there previously (picture). Now I can even move the Mesh around in the blueprint as if I added it with the blueprint instead of script. Awesome!

![5996-transform.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/5/0/25058c50767cbd4f2db137df0bca3039f30b0063.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_44db827a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_44db827a](https://forums.unrealengine.com/u/anonymous_user_44db827a)\
**Post date:** [May 9, 2014, 7:55pm UTC](https://forums.unrealengine.com/t/how-can-i-set-the-size-of-a-mesh-using-code/282751/7 "2014-05-09T19:55:11Z")

</div>

Thanks for your reply! I have, however, found a solution in C++ (it was right in front of my eyes, as always :P)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e94eba37](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e94eba37](https://forums.unrealengine.com/u/anonymous_user_e94eba37)\
**Post date:** [January 1, 2016, 1:16pm UTC](https://forums.unrealengine.com/t/how-can-i-set-the-size-of-a-mesh-using-code/282751/8 "2016-01-01T13:16:44Z")

</div>

Excellent! You can simply double the size of your mesh by calling `MeshComp->SetWorldScale3D( FVector( 3 ) );`, no need to mess around with blueprints 🙂
