How to set object visibility based off Line Trace hit

I am working with a top down game and I have a Line trace set up from the player camera to the player. I have figured out how to get certain objects to disappear when hit by the line trace, but I am struggling to figure out how to set them back to visibile when not being hit.

To my understanding the line trace sees the object being hit and executes the set visibility function. But when the object is no longer being hit, it has no way of knowing which object it was previously hitting in order to reset the visibility.

1 Like

You need another piece of code which scans the objects in the level and makes them visible, repeatedly.

If it’s just static meshes you’re dealing with, that’s all you’ve got.

If you’re dealing with blueprints, it could be a lot easier. When the line trace hits, send a BP message to the BP saying, go invisible.

The BP makes itself visible again after a certain amount of time, if it hasn’t been hit again.

So I created a blueprint to use as the roof, how exactly would I call for that roof BP to go invisible? The line trace is located in the Player BP.

So you make a blueprint interface:

In there:

311124-inside-bpi.jpg

( compile and save ). Inside the roof, you need to set it to ‘implement’ that interface:

Then you put this code in the player, when the trace hits:

And finally in the roof BP:

1 Like

This will work for now! Thank you so much :slight_smile:

Great thing about interfaces, is the responding actor can do anything you code them to when they get the signal. Change color / size / vis etc…

1 Like

How could I make this work if I wanted to do this to an actual roof asset? Would it be like this or different since its no longer a BP?

It really depends on the asset. It might be a BP, in which case you have to hack it a bit. If it’s just a mesh, you either back to scanning everything or make a BP and put the roof mesh in it.

This is awesome, thanks guys. Firstly to the op for getting 95% of the way there, and then to ClockworkOcean for providing the solution. I’ve been round the bends over the internet this afternoon looking to figure out how to get some blueprint meshes hidden when in the way of the camera, and this has answered it! But I’ve also learnt another piece of the puzzle in how to get blueprints to communicate via the interface. If only I could figure out how to make the actual trace line itself, a bit wider.

1 Like

The line trace has no width, try a sphere trace :slight_smile:

1 Like

this leads to having a flicker every second, which still kinda sucks.