How to make a trigger box to switch materials by pressing a button from the touch controllers?

Hello Guys, I’m frustrated here,
I’m using the UE4 VR Template and Migrated my project to that template to be able to use the HMD and touch controllers in the level.

But I wanted to add a Trigger_Box that can change the material of a StaticMesh by pressing the “B Button” on my touch controllers.
and make the effect within the overlap area of that trigger box.

I’m new to the VR Dev. and my knowledge is still in the beginner phase, so it someone managed to make the hands in the project template provided with the engine to interact with trigger boxes and other stuff please help me, and also i wanted to make a door open and close when i reach out my hand and press the tigger button on the handle :smiley:

Thanks a lot.

Don’t be frustrated, that’s just part of the learning process we all went through at a certain point.

Here are few pointers for you:

  • Create a static mesh actor blueprint which contains the mesh (let’s say a cube) whose material you want to change
  • Add a collision box volume around it, make it larger than the contained mesh. Make sure it is set to generate overlap events and is set to OverlapAllDynamics
  • Select the collision box and right click in the Event Graph, look for the On Begin Overlap Event. This is the event that is triggered every time another actor “enters” the collision box.
  • When the Begin Overlap event is triggered, you have to check that the actor entering the volume is one of the motion controllers. You do that by Casting to BP_MotionController and checking that the cast is successful. If the cast is successful, set a boolean variable bIsOverlapping? to True, otherwise set it to False. The value of the variable should be False to start with.
  • Define also the On End Overlap Event for the trigger volume and when it fires set the bIsOverlapping? variable to False.

Now the tricky part.

Once the overlap has happened (bIsOverlapping? is True) you want to change material using the B button, which is Motion Controller (R) Facebutton 2. In principle the input events should be processed by the Motion Controller itself or by the Pawn, but then you would need a way to communicate to the cube actor that the button as been pressed. You could do this with an interface, but that is adding an extra level of complexity for you.

Let’s instead have each cube actor receive the Motion Controller (R) Facebutton 2 event and, if bIsOverlapping? is True, change the material of the corresponding static mesh.

For that:

  • Add a Motion Controller (R) Facebutton 2 input event to the cube actor
  • Click on the Event and uncheck Consume Input. This will ensure all cube actors receive that input and not just the first one on the input stack
  • In the Details panel of the cube actor, set Auto Receive Input to Player 0
  • Out of the Motion Controller (R) Facebutton 2 event, check with a Branch if bIsOverlapping? is True and, if it is, change the cube material (I leave this part to you)

That’s it. Try to implement it and post again here if you face issues.

Hello vr_marco
Thanks really for replying so quick, I’ve been trying to understand all you’ve stated above for a couple of days, and I think I’ve managed to understand a little from it and from other external sources.

Your step-by-step explanation you stated here is really straight forward and I really thank you for that it was really helpful, but i’ve made all of these stuff and came out with this result but i’m afraid it is not working for me at the end. I will show you what I’ve done here and please tell me if I’m doing anything wrong as I’m really a NOOB in these stuff :smiley:

and to mention the teleportation (the NavMesh) now is not able to detect that area for the collision box I’ve made in the blueprint and when i teleport it’s all messed up i think. it’s not detecting the floor as the ground for teleportation.
I’ve linked the two images to help you understand my problem.

and again I really thank you so much for saving me in this :smiley:

Can you show where did you place the actor with the Trigger Box in it and how its hierarchy looks like?

The issue with the NavMesh could be a different one. You didn’t mention it earlier. It could be that the way you have created the actor interferes with the NavMesh generation.

Now that I see your application, I am also doubting that using a Trigger Box etc. is the right choice. You may be better off with some Line Tracing. You basically point with the controller the mesh you want to change material for and, by pressing a button, you “ask” them to change their material. It’s a much nicer and practical interaction model.

Yes the line tracking will be much more better of course :slight_smile: but i dpn’t know how to do that actually. and putting in consideration that i’m using the VR template as it is, as when i tried to make my own GameMode and controllers and that stuff it didn’t work well with my Oculus, (don’t know why : sure i did something wrong or missing :smiley: )

and about the actor , it is actually a floor or a wall i want to change the material to. can you help me with something to start with?
and thank you really much I appreciate your concern.

To use Line Traces basically you fire a ray from your hand and if it hits an object for which you know you can change the materials, then you can trigger the change with your controller button. It is not particularly complicated, but it requires a good knowledge of Line Trace by Channel, Hit Results, etc.

I would suggest you to start from the basics and build up your knowledge from there. Here is a YouTube tutorial showing pretty much what you need, just not in VR. Once you have understood in full how this works, then you can come back here to get some help to port it to VR.

If you search on YouTube something like “UE4 archviz material change” you will find many other tutorials similar to the one above. Check how the interaction works and think how you can do something similar in VR.

When I have time I may make a YouTube tutorial showing how to do it directly in VR.

Thanks so much, i will try to follow what’s in this video and come back with the results i get.

I already know how to change material in first person shooting. Can you show me how to make it work in VR template?

Hello, is there a tutorial on how to do change material while in VR?

ok I managed to make it work, everything is ok but now I am trying to insert text render and to have it visible only when inside the collision box…any thoughts?

Hi, can you please share how you managed to make it works؟ Thank you

Hello Guys,

can you explain me how I can create a changeable material in VR mode with Oculus Rift?

I would want to reach this result: UE4 Changable Real-Time Materials (ArchViz) - YouTube ,
but I don’t know what I have to change for this visualization mode.

Is there someone who can help me, please?

Thank you, Angela.