# How to set object visibility based off Line Trace hit

**URL:** <https://forums.unrealengine.com/t/how-to-set-object-visibility-based-off-line-trace-hit/470209>\
**Category:** Rendering\
**Tags:** line-trace, visibility, unreal-engine, top-down, Blueprint, question\
**Created:** [August 23, 2020, 7:50pm UTC](https://forums.unrealengine.com/t/how-to-set-object-visibility-based-off-line-trace-hit/470209 "2020-08-23T19:50:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![B3P](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@B3P](https://forums.unrealengine.com/u/B3P)\
**Post date:** [August 23, 2020, 7:50pm UTC](https://forums.unrealengine.com/t/how-to-set-object-visibility-based-off-line-trace-hit/470209/1 "2020-08-23T19:50:51Z")

</div>

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.

 ![311108-linetrace.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/7/5/e755b20ae0d4617855b93cecf297871c9b2469b9.png)

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.

 ![311121-linetrace2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/a/7/1a79c68b5f39da9a27cf426338a8081c3908767c.png)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [August 23, 2020, 8:00pm UTC](https://forums.unrealengine.com/t/how-to-set-object-visibility-based-off-line-trace-hit/470209/2 "2020-08-23T20:00:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![B3P](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@B3P](https://forums.unrealengine.com/u/B3P)\
**Post date:** [August 23, 2020, 8:21pm UTC](https://forums.unrealengine.com/t/how-to-set-object-visibility-based-off-line-trace-hit/470209/3 "2020-08-23T20:21:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [August 23, 2020, 8:56pm UTC](https://forums.unrealengine.com/t/how-to-set-object-visibility-based-off-line-trace-hit/470209/4 "2020-08-23T20:56:09Z")

</div>

So you make a blueprint interface:

 ![311123-bpi.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/b/5/1b5fc53baba10de8beda56bbcc2e45557a25854b.jpeg)

In there:

![311124-inside-bpi.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/f/3/3f31a02f9ffd864fde3aedfe32a48758e11ded19.jpeg)

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

 ![311125-add-bpi.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/9/0/590fcfaf131c506535c7993fb4151302262e3e4f.jpeg)

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

 ![311126-from-player.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/8/6/e86a2e4008b51908c2f7dd1bee0ce6edc0d59e53.jpeg)

And finally in the roof BP:

 ![311127-in-roof.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/b/f/abf105b8d86c59d8af4911916e6503ba0cbc64f7.jpeg)

---

<div class="post-metadata">

**Author:** ![B3P](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@B3P](https://forums.unrealengine.com/u/B3P)\
**Post date:** [August 23, 2020, 9:17pm UTC](https://forums.unrealengine.com/t/how-to-set-object-visibility-based-off-line-trace-hit/470209/5 "2020-08-23T21:17:36Z")

</div>

This will work for now! Thank you so much 🙂

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [August 23, 2020, 9:21pm UTC](https://forums.unrealengine.com/t/how-to-set-object-visibility-based-off-line-trace-hit/470209/6 "2020-08-23T21:21:02Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![B3P](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@B3P](https://forums.unrealengine.com/u/B3P)\
**Post date:** [August 23, 2020, 9:22pm UTC](https://forums.unrealengine.com/t/how-to-set-object-visibility-based-off-line-trace-hit/470209/7 "2020-08-23T21:22:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [August 23, 2020, 9:25pm UTC](https://forums.unrealengine.com/t/how-to-set-object-visibility-based-off-line-trace-hit/470209/8 "2020-08-23T21:25:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ant\_march](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ant\_march](https://forums.unrealengine.com/u/ant_march)\
**Post date:** [January 5, 2021, 6:39pm UTC](https://forums.unrealengine.com/t/how-to-set-object-visibility-based-off-line-trace-hit/470209/9 "2021-01-05T18:39:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [January 5, 2021, 6:51pm UTC](https://forums.unrealengine.com/t/how-to-set-object-visibility-based-off-line-trace-hit/470209/10 "2021-01-05T18:51:59Z")

</div>

The line trace has no width, try a sphere trace 🙂

---

<div class="post-metadata">

**Author:** ![kotatheninja](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kotatheninja](https://forums.unrealengine.com/u/kotatheninja)\
**Post date:** [February 6, 2024, 10:28pm UTC](https://forums.unrealengine.com/t/how-to-set-object-visibility-based-off-line-trace-hit/470209/11 "2024-02-06T22:28:51Z")

</div>

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