Author Topic: Substance on Unity Submesh via Script  (Read 3750 times)

Is it possible to place copies of a single Substance on each submesh of a Unity game object and vary their parameters independently of each other?

I’ve created a script which successfully generates the submeshes and allocates the Substance to each but all copies simply reflect the parameter values of the last submesh updated. My first assumption is that the code is incorrect but I need to check if I’m attempting the impossible before further debugging.


you have to duplicate the substance in the project window and then apply it to make it individually accessable.
From my point of view, this isn´t very efficient, as you duplicate things, that are common to each instance. For example, if you have metal and rubber as part of your graph, it would be enough - theoretically speaking - if they´d show up / exist only one time.

I think, it would be a good idea for allegorithmic to give the management of substances within unity a thought. A little substance node manager, that gives you the ability to trigger common properties for example (,1144.msg6993.html#msg6993)... Or that lets you duplicate only the part of the substance, that´s used individually...

michael_11 – Thanks for feedback!
(Stops banging head against wall and prepares to re-think strategy)

If you don´t need too many individual shaders, you could setup the substance with a number of graphs (for each shader/submesh) within substance designer; the advantage of this approach is, that you reuse your base materials within the graph - which is efficient. And you can edit your submeshes´ materials individually.
But still the question remains, why not do this in unity / how about giving the user a tool to manage those things inside unity. Coders out there, isn´t this a nice challenge :)?

AFAIK if you have more than 20 graphs within your substance file, you should consider splitting them up in different substance files (sbar´s) or duplicate the substance inside the project view of unity.
Again, as a result we get a lot of substances, which is not as elegant as it could be.

(Which is my issue with a bunch of models that all share the same substance, but have individual input maps, which is why I have to duplicate the substance for each model...)
Last Edit: June 28, 2014, 03:33:59 pm

Michael_11 -> strategy
Originally I wanted to keep the number of graphs flexible via run-time script implementation but for the moment will manually create ten re-named duplicates within each package.  I’m not using imported bitmaps but generating everything from FX-Maps.

Code-wise I’ve now managed to duplicate the graphs at runtime using SubstanceImporter.InstantiateMaterial but these are just added to the package in Unity along with their respective outputs and continue to exist after program termination – which is no real improvement on the manual method. I just need temporary graphs for use in play-mode leaving only the original package at completion. I’d like to spend more time experimenting with this but existing prototype code examples are extremely sparse and a competition beckons at the moment.