Resize Actor/mesh depending on viewport size
Hello, I'm trying to resize an actor and it's mesh component according to the current viewport size. So here's what I'm doing:
First to get the viewport size and call the resize function:
Now in my ResizeTo2DViewport function I'm just setting the scale of the actor and it's mesh:
I'm dividing by 38 because unreal's units are equivalent to 1cm and 1cm is kind of 38 pixels. So i'm dividing the viewport size by 38 to convert it to units so i can set the scale. When i do that, the actor and the mesh fill the screen but even when i divide by 100 or higher number it keeps filling the whole screen.
What i want to do is to scale the actor and set some margins between the viewport and the actor, Imagine if it's a plane or a cube, i want it to fill the screen minus 10% of the viewport size to each side.
How could i do that? is my approach a good approach? What better solution would you recommend?
First of all, the call of SetWorldScale3D after SetActorScale3D should be kinda reduntant, asuming your FieldMesh is a subcomponent of your Actors RootComponent, or is itself the RootComponent.
Furthermore, the Scale Value should be a multiple of the Standard Value. Imagine this: Your Mesh is made by an Designer and is imported into UE4 such that it is 50cm*70cm*30cm (X*Y*Z). This will be his standard Value when placing into the World -> Scale = 1.
So if you call SetActorScale3D(1.5, 2, 0.5) on a Actor with this Mesh Component, your Mesh will be 75cm*140cm*15cm (50*1.5, 70*2, 30*0.5).
I would suggest you, to take any reasonable Screensize Value as your Standard Value.
For example let FVector2D(640.f, 480.f) be your standard Value. Now just divide the Components (.X, .Y) of your actual ScreenSize by the Components your Standard Value and you will get appropriate Scale Values.
Please let me know if this works, or if anything is total bullshit i just wrote.
Follow this question
Once you sign in you will be able to subscribe for any updates here