When you use a Widget
inside an actor to be able to place it in the world, is there a way to disable the effect of Directional Light
and Post Processing Volume
has on it and look the same as if you place it in viewport?
World space Widgets are affected by Post Processing and other scene effects by default.
However, the only way around as far as I know is it use Screen Space rendering.
The best way to implement this entirely depends on your use case, but for argument’s sake I’ll use “Health bars”.
Inside your widget, when an actor (Preferably with a “BPC_HealthBar” component) is initialized, the Hud adds a screen space Health bar to a canvas, and continually sets the position and scale in 2D space based on the position of the Actor in world space. (It will also need to Cull the Health bar when it is no longer in the player’s view)
Widget Components do now implement a “Screen Space” option, but it might not always give the desired results, so if you wish to have more control, you need to manage this in your own widget.
With a bit more knowledge about your use case I might be able to offer a bit more advice about how to implement this in as painless a way as possible.
Firstly, my game is third-person, multiplayer.
Right now I have a widget that contains an image and some text and it is placed at the beginning of the map. All the maps at the start have this type of actor, a widget with some static meshes around it to make it look better, which contains some info about the map, while the players wait for the others to join and can walk around it.
But if I think about the whole game, I will have two other scenarios:
- A Widget placed above the player character with his/her name (with a toggle at the start if they want the name to be visible or not) and maybe under it, but really small chances, a health bar
- A Widget with the health bar above enemies for maps with PvE
The rest of the widgets are added to viewport as they aren’t linked to specific actors in the world.
Great. Thanks for adding that.
Unreal engine sadly doesn’t offer much support with regards to render passes or the order that certain elements are rendered.
So, as far as I know, world space widgets will always be affected by post processing. I wish this wasn’t the case, but in Unreal we don’t get much more control over elements like this.
It sounds like you may need to utilize the screen space approach.
Widget offers many ways to Project a 2D widget to your screen using 3D coordinates. This includes scale too by calculating distance.
Perspective is where this can get tricky, it’s unlikely you’ll need this level of detail, But if you absolutely need it, Widget does offer Skewing as an option to affect widget transforms which may be possible to calculate with some custom vector math.
But without the complicated perspective calculations, screen space widgets aren’t as intimidating once you get going. You’ll essentially need to create a Map of Actors:Widgets inside your Widget Blueprint, and every tick: Create the Widget if it doesn’t exist …otherwise… update its position and scale on screen. (And if the Actor isn’t valid, Remove the widget from parent).
Best way to do this is to create a Blueprint Component with a variable for the Type of widget it needs to display, and when it initializes on begin play, I needs to send a reference of itself to the WBP, so the WBP knows to display a widget for it, whether that’s a Health Bar, Screen, or Player Name.
I hope that helps.
Thanks, I will keep this in mind. I kinda do understand what you mean, and yeah it may be harder the first time. Once you know how it works it will be easy to replicate for each scenario. But, there is a but, unfortunately I would need to play around with perspective as well for my case, but, yet another one, I did found an acceptable way for now, hence part 2 below.
I said “keep in mind” because I played around with the material for the widget component, and I got it to look good enough, by changing it’s formula for emissive color.
It really is unfortunate that they don’t offer a way to decouple widgets from the rest of the world and keep then nice looking. I haven’t played yet with FSR/DLSS, but being part of the world, I think those will affect them in a bad way in some scenarios.