Toggle object material on trace hit
First, a brief explanation of the game I'm trying to make.
I'm creating a fps puzzle game that involves picking up blocks/other shapes and using them to unlock puzzles. Part of the puzzle system involves the objects having different weights. I currently have it so that I can pick up objects, and the speed at which I can move them around slows down depending on their mass. They also slow down play movement speed depending on mass.
I'm currently trying to add functionality to my game that would make it so when I look at an object, it turns transparent, and displays its mass in the center of it, and when I'm not looking at the object, it sets itself back to its default material, basically a first-person "mouse-over".
I'm trying to do this via trace from my player camera. I have no problems setting an objects material when the trace hits it, but setting it back to default is proving extremely challenging. I've tried using a blueprint interface, and this DOES work, however, since I have to call the exact blueprint that I want to change, its not a very flexible system. This would actually be my ideal method, so if there's some way for me to dynamically get the blueprint that my trace hit, and then send an event to that specific blueprint, it would be awesome... but as far as I can tell, there's no way to do that.
The other option I tried was to capture the objects material when the trace first hits it, and then set it back to that after the "mouse-over" is complete. The problem is that once my trace hits it, its material changes to the transparent version, and then it just captures that material rather than the default one and the object gets stuck in transparent mode.
Does anyone have any suggestions on how I might solve this? I'm sure there's some tricky way to achieve everything I want, but I'm fairly new to scripting in general, so this is currently evading me.
Any help would be greatly appreciated!
asked Mar 28 '14 at 10:37 AM in Blueprint Scripting
Had a similar problem. In the end I captured the original material in a variable before changing it the first time.
Then I created a timer which would reset the material after 0.1 s which gets cleared each time, the hit function is called. So when there was no hit for > 0.1 s, the object's original material was applied again.
It's clunky, but it works.
answered Apr 20 '15 at 10:00 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here