Show/Hide objects with raycast

Hello all,

I’m trying to make a system of button activated by raycast and who make appear or hide multiples objects when “pressed”.
I have the raycast who print me the name of the object who’s working but now I’m stuck, and I have no idea how to continue…

Any help is welcome :slight_smile:

You can get the hit actor of the raycast and cast it to the object and within the casted object you can call your desired function.

My raycast result is that, what function can I had to cast it to the object (my button if I undestand) ?

make a function in every object that makes stuff visable and insvisable and cast to what your looking at and activate that function

Ok so this is what I have now, when the raycast hit something, the object disapear an appear if I click a second time. The issue now is that I want that only when my raycast hit the “Button” mesh.

For that, I need to make a blueprint in any object I want to set visible or not ? Or a blueprint on the Button ?

The picture you replied at 678GUY the only thing missing is before the flip flop cast it to your button first, if it is a success then proceed to setting visibility if it returns fail do not do anything.

Ok I understand, but did you have the exact name for that success/failed function ? :slight_smile:

I don’t know if my explanation is a bit confusing sorry haha, Is your button a blueprint or also an actor within the map?

If it is an actor within the map and not a blueprint you cannot do casting.

IF BUTTON NOT A BLUEPRINT

  • Add reference to the level blueprint
  • Do an equal test if the actor hit by the linetrace and the button reference is the same.
  • If it is the same do the visibility functions.

IF BUTTON IS A BLUEPRINT

  • After the linetrace do a Cast to your Button blueprint

  • Link the upper part(successful cast) to your visibility function.

126707-cast+node.png

It was so simple… Thank you a lot StillAlive ! :slight_smile:

No problem glad to help :slight_smile:

Just a last question about it, now if working when I click on one object (my Button). But if I need to do it whith differents buttons for diferents result, how can I make a “switch” function after mine LineTrace ?

Thank’s again for your time !

I know you got your answer, but for a more modular approach look up interfaces. With interfaces you don’t have to do any casting at all. Right now you always assume the actor hit is the actor you want to hit. Just a tip if you want to expand your functionality in the future. :slight_smile:

I have limited knowledge in UE4 this is the way I would do it. This might be not the most efficient way to do it, there might be other ways to solve it that is better than this.

I assume your button is only an actor in your level.

You make an array containing all your button reference. Arrangement in making the array is important.

126722-add+to+array.png

After adding them to an array. Add this after your linetrace node.

Every time you click it will read your array and check all the buttons you placed there comparing it to the hit actor of the line trace, when the proper button was found it will continue to the switch on int.

0 is for the first item in the array, 1 is for the second, the rest follows.

For example button one will make something fly, you put the fly function on the 0 part of the switch on int. The second button will make something disappear, put the disappear function on the 1 part of the switch on int.

The default as the name implies the default function to be called when the integer range exceeds the declarations.

I reccommend you to make a blueprint that can be the parent of all your buttons and you can reduce that making of array to this. There arrangement would be the first blueprint you placed on the map will be the first item in the array.