Trigger overlap volume only if static mesh is visible in frame..

Hi, I need help. I have set up blueprint to change the Material of static mesh in Runtime. I have put overlap trigger volume for static mesh to show the ‘Material option’ made in UMG widget blueprint’. Whenever player overlaps volume UMG widget Appears on screen then player can click and change material for that static mesh.

everything is working fine but the problem is when player overlaps the volume, even if the static mesh is not in the frame 'Material option UMG widget 'appears on screen which is confusing for the player. I want UMG widget to appear only if that specific mesh is 100% or at least 50% visible in the frame. how can i do that?

can anybody help?:frowning:

Hi, depends on how you wanna do this/what you want to achieve.

(1) there is a node called “was recently rendered”

(2) you can do a dot product from your camera forward vector with the normalized vector from the player to the static mesh, to see if the static mesh is in front of the camera. This obviously has its limitations as the static mesh has a certain extend

(3) as soon as the static mesh actor triggers the overlap do a couple of line traces from the player camera position with the player cameras forward vector as rotation and add some random rotation on top of it. Then see if one of those traces hit the static mesh

I think I would go with a combination of (1) and (2), so see if it was recently rendered and then make sure it is somewhat in front of the player.

Hi man ,
There are some ways to check it.

A simple way to make it is :

Get the Staticmesh location.
Get the player camera Vector Forward.

Take the Staticmesh location - the player location. , Simple Vector - Vector
This will give you another vector that is : From Player toward the Static mesh.
Use the node Normalize, to get the Normalized version. This is The N_Vector

Now just use an Vecctor Egual == to check if
the Camera Vector is == to The N_Vector
This if will be true when the player look in the direction of the static mesh.
How much Precisely? You set it in a variable in the node,
How much they have to be similar for the check to be true,
Set it to something like 0.8 and tweak it .

Remember that this work with the location of the mesh.
If you have a mesh long 100 m , clearly it wont work properly
Short little meshes work fine

Thanks for suggestion. As I am not a programmer so i guess “was recently rendered” would be simplest method for my requirement. I tried to add “was recently rendered” node but its not working in my case what i am doing wrong? Please have a look at attached screenshot of blueprint.

Long time since I used that node and I can’t open UE right now, but first of since you only want to execute this logic when the player overlaps this trigger box, I would compare the “Other Actor” with “GetPlayerPawn” and only continue if both are the same.

As for finding where the problem is, I would do some prints. So first of do a print to see if the “BeginOverlap” is even triggered. Then print the “Static Mesh” to see that it is not none. And then print the result of the “WasRecentlyRendered” node.

Hi, I tested in Mathew Wadstein ‘WTF Is? Was Recently Rendered’] tutorial project file just to test if its working or not, found out its working. it seems there’s some problem with Player controller in my project as i am using ‘Arch-viz controller’. I’ll check later with that.

I have still reached half way only.
Inside tutorial project file i created small test scene similar to what i want to achieve . in that scene “WasRecentlyRendered” is working fine but there is a problem.

There is two possible functionality -

  1. (Static mesh is in the frame) player walks and overlaps ‘trigger volume’ ‘UMG widget’ gets added to view port. (working fine)
  2. (Static mesh is not in the frame) player walks and overlaps ‘trigger volume’ ‘UMG widget’ doesn’t get added to view port (till here working fine) but while Player stays inside ‘trigger volume’ and turn around now Static mesh comes in the frame but ‘UMG widget’ doesn’t get added to view port.

Hope i have explained everything.

is there any solution for this?

Thank you

That’s the expected behavior from the code you’ve shown above =)

You’re only checking for adding the widget the moment the player walks into the trigger. That’s a one time event. But for what you want you would need to check this constantly. So either use a timer or tick (I would generally go with a timer).

So player walks into the trigger -> on begin overlap is called -> there you set the timer -> inside the timer you use the “WasRecentlyRendered”, if so display the widget, if not then maybe remove the widget depends on how you want it to behave

On End Overlap -> clear and invalidate the timer and remove the widget if it is valid

Hi, its working, however i want to know if static mesh is in sub level which is always loaded and i want to reference static mesh from there how can i do this?

I never seriously used sub levels, so no idea but you might wanna open a new topic for this one and put a link for the new topic in here for anyone who might have the same question and and reads this topic here.