x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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->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.

Product Version: Not Selected
Tags:
more ▼

asked May 07 '14 at 05:52 PM in C++ Programming

avatar image

Borzi
174 43 39 48

avatar image Borzi May 08 '14 at 07:05 AM

Nobody have any feedback for me?

avatar image AddictArts May 08 '14 at 08:54 PM

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.

avatar image Borzi May 08 '14 at 09:04 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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!

alt text

transform.png (18.2 kB)
more ▼

answered May 09 '14 at 07:54 PM

avatar image

Borzi
174 43 39 48

avatar image sick Jan 01 '16 at 01:16 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

https://wiki.unrealengine.com/Templates_in_C%2B%2B

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

more ▼

answered May 09 '14 at 03:30 PM

avatar image

Rama
10.6k 446 345 1088

avatar image Borzi May 09 '14 at 07:55 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question