Widget Scaling at Distance

image

In the above picture you can see a widget I have attached to characters. In the background you can see the widgets overlapping eachother, because they arent scaling down to fit the perspective. How do I fix that?

You need to calculate the distance between actor with widget and camera - then scale widget size accordingly

that doesnt sound easy

Not sure if this is exactly what your looking for, but you could add a box trigger inside of the characters blueprint editor and extend it to how long it looks big, then how long it looks small, for example
when the player steps into the box trigger of the character the widget gets bigger and when they exit it gets smaller, all you have to do is create 2 widgets 1 small, 1 large.

It isn’t primitive, but not so complicated. Actually, you just need to get camera actor inside widget blueprint and then you can easily get distance between two locations by using this Distance (Vector) | Unreal Engine Documentation

Or another option for you is to use World Space in your widget component.
You might also need to rotate them to face the camera.
image

Possible. I could have each widget point to a location in space. the problem there is, if its actually at the camera location, which be more at an isometric location, … afraid the angle difference would be noticible, but ill give it a shot.

then apply some math to the distance to determine scale?

Let’s have a look at how does it work in my project
Here is the enemy’s pawn with a widget setup. Pay attention that I cast enemy’s widget and send ref of owner’s pawn


1a-enemy pawn

Then in the widget’s graph itself, I use this ref to get any variable that is needed (here you can call the pawn’s location)


And here is the widget designer, I anchored the HP bar on the center of the screen. Here are progress bar sizes X and Y that you can change on the fly

I don’t know how you implemented such HP bars on all pawns but you just need to have

  1. Enemy’s pawn ref → get location (vector)
  2. Camera’s pawn ref → pull out camera component → get location (vector)
  3. Distance between two vectors → distance value(float)
  4. Some logic that will change the progress bar’s size in the widget accordingly to the float value

I have something similar. Im going to try and incorporate what you have into it. Interestingly enough, I dont actually have any graph set up for the actual widget in question, this graph is actually on the Parent character class for the AI pawns.

So I found I can set the render scale of the canvas which is the root of the whole widget. I put in static 0.5x/y to test and it works.

I then put in a reference to the Playre and Character and got the transform of both and printed to screen. It prints out the right info, which means i can do math on it, but i notice i also get runtime errors included in the screenshot.

This ‘access none trying to read property…’ is a constant PITA… its here, and in other things im trying to put together. Im having problems wrapping my head around whats wrong here. I clearly have the reference correct, but … no clue what im doing wrong.

Use - “is valid” node to clear log

So i found out that my REF issues are becaue they are effectivily NULL and have to be SET or intialized with the value first. Which is irritating because I specifically indicated in the VAR itself what i was trying to target.

Also trying to create a REF for a widget outside of creating it initially seems impossible.

It might help you

1 Like

Ive actually watched a few of his videos, and have considered blueprint interfaces… which could solve some other reference issues im having with calling a variable from a widget inside another widget.