Hide a 3DWidget

Hi , i’m about to create a blueprint who allow to the players to see their names on top of each player with a 3DWidget. The problem is, that i want to hide the name if there is an object between the player field of view and the other names of the other players.

Greetings,

You can use two checks to achieve that, first one that checks if the player is close enough to any of the other characters by looping trough all of them every 5th frame or so, then if some are close enough make another check using a line trace from the player to that/those characters to ascertain if the player can see them, (the only reason for delaying the checks somewhat is to try and minimize any performance impact if you are checking against many characters/complicated terrain collision).

This type of checking is kinda basic since it ignore foliage or other types of partially covered characters, but it should work for you at the moment based on your image so I would recommend it.
You could also try and put up a system using ue4’s perception components but hat involves more options and can sometimes be more complicated to use cleanly.

Im sorry , Im beginner in unreal engine and i have a difficulty to understand what i need to do . If you can take a screenshot of the blueprints . Thanks you !

make an array of type actor reference in your character with references to all the enemies at begin play, either by making each enemy “add” self by casting or maybe as a temporary solution use a get all actors of type node if you only have one actor type atm.

do a foreach loop using that array.

Inside that loop make a branch and check the distance to the actor, (location - location < the distance you want), if true make a linetrace to that actor from you player character, if the trace returns the same actor as you are checking in your loop atm, (drag a node from the loop actor ref = it to the actor hit from the trace), then cast to that actor and run a function in it displaying its name.

Im at work atm, so I could possibly make a graph when I get home, hope that helped.

Thanks you ! The widget work really nice :slight_smile:

Awesome :smiley: Make sure to mark this answer as accepted so the questions shows up as solved

I try this but i have little knowledge in unreal engine and its difficult i dont really know what i do , when you speak of “array and references to all the enemies” I didn’t succeed :confused: if you can screenshot your blueprints . Really thanks for what you do .

You’re likely using the “Screen” option instead of the “World” option for your Widget component. In the settings for the Widget Component, change the Space option to World instead of Screen. Screen will render the text in screen space which means it will always clip in front of Objects in the world.

Let me know if this helps :slight_smile: