x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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 :)

Antoine

Product Version: UE 4.14
Tags:
more ▼

asked Feb 16 '17 at 02:57 PM in Blueprint Scripting

avatar image

Antoine Provost
3 1 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

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.

more ▼

answered Feb 16 '17 at 03:17 PM

avatar image

StillAlive039
182 9 10 19

avatar image Antoine Provost Feb 16 '17 at 03:51 PM

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

alt text

avatar image StillAlive039 Feb 17 '17 at 01:45 AM

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.

avatar image Antoine Provost Feb 17 '17 at 08:23 AM

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

avatar image StillAlive039 Feb 17 '17 at 08:43 AM

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.

alt text

cast node.png (19.3 kB)
avatar image Antoine Provost Feb 17 '17 at 08:47 AM

It was so simple... Thank you a lot StillAlive ! :)

avatar image StillAlive039 Feb 17 '17 at 09:01 AM

No problem glad to help :)

avatar image Antoine Provost Feb 17 '17 at 09:02 AM

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 !

avatar image StillAlive039 Feb 17 '17 at 11:21 AM

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.

alt text

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.

alt text

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.

alt text

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Feb 16 '17 at 10:21 PM

avatar image

678GUY
141 33 32 38

avatar image Antoine Provost Feb 16 '17 at 10:54 PM

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 ?

alt text

Antoine

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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. :)

more ▼

answered Feb 17 '17 at 09:16 AM

avatar image

SirDouchebag
37 5 6 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question