playMaker

Author Topic: Instance material at runtime?  (Read 1266 times)

indeed

  • Junior Playmaker
  • **
  • Posts: 85
Instance material at runtime?
« on: October 15, 2018, 09:47:41 AM »
Hi, is there a way to instance a material at runtime? I'm in a situation where it makes the most sense to use sharedMaterial, but that has the annoying problem of actually modifying the mat file in Assets. It doesn't reset on exiting playmode.

What would be ideal is to instance the material at runtime, then sharedMaterial changes can be applied to the instance, which would then revert back on exiting Play mode.

Basically looking for a Playmaker version of Spikeh's solution here:  https://answers.unity.com/questions/396347/how-to-stop-renderersharedmaterialsetcolor-writing.html

GonerGames

  • Junior Playmaker
  • **
  • Posts: 53
Re: Instance material at runtime?
« Reply #1 on: October 15, 2018, 03:40:58 PM »
Using Arraymaker I set up an Hash table of materials. Then during runtime I use Hash Table Get to get the material I need and then use Set Material to change it out on the fly.

It won't save the changes when you exit. You'll need to use Easy Save or Player Prefs for that.