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

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->bGenerateOverlapEvents = false;
	MeshComp->CastShadow = true;
	MeshComp->bCastDynamicShadow = true;
	MeshComp->AttachTo(CollisionComponent, "");

	//Set init Values for mesh component

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.

Nobody have any feedback for me?

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.

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


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


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


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

//replaced MeshComp->SetRelativeSacle

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!


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

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