Material change on tap
I was trying to figure out a way to completely change the material of a mesh with a tap. I'm working on adding hair buns on someones head with a lens and I was wondering how to make it so that the user can tap the screen to cycle through different hair colors to change the material to match their hair color. If anyone knows a way to do this or an even better way to achieve the same result that would be super helpful. Thanks!
Hi Joshua,
Here's a script that will cycle through materials, applying them to a MeshVisual you specify. Add it to the "Initialized" event on a ScriptComponent, then hook up your MeshVisual component and Material assets.
You can also check out this guide for more scripts and tips on cycling through items on tap. I adapted one of the scripts in there for the script above. You can also modify the script to use vec4 instead of Materials, if you'd prefer to use a single material instead and cycle through colors on it.
Let me know if you need any more help!
Thanks,
Jacob
Thank you so much! This was exactly what I needed :)
I get this every time I complete my cycle of my two different items:
11:04:56 TypeError: cannot write property 'enabled' of undefined
at activateNextItem (Change on tap-Script:20) preventsyield
When I push lens to device it works but then it reach the end of the cycle it says lens error.
Hey Martin,
I think you may actually be using the script from this post? If so, did you modify the script at all? It looks like line 20 is blank in the original version.
If it's the unchanged script, I'm not sure what could be causing that, since it's working for me with two objects. Is it possible one of the objects is getting destroyed? If not can you post the full script you're using?
Thanks,
Jacob
Is there a way you can clear the other materials from the scene entirely so that it doesn't impact the FPS or Ram usage? When looking at the FPS and ram, they both go up every time I cycle to a new material until I've cycled through them all. Could there be a way that only one material impacts the scene?