Author Topic: Is there a way to remove generated textures via script?  (Read 628 times)


So I'm rewriting this asset that uses Substance for my own purposes.  I never heard of Substance before that so I'm a bit new to it so please bear with me.

What I'm trying to do is essentially generate planets for a level procedurally. 

Here some of the characteristics/requirements:
- There can be many planets on this level.
- Each planet has a type: eg. earth, lava, ice, gas, etc.
- There could be many planets of the same type. 
- These planets (of the same type) should look differently from each other.

This asset has a number of Substance Graph objects that represent each of the planet types (biomes) along with other characteristics like clouds and so on.

Using a "Dust/Barren biome" as an example, it can take a random seed and other properties and generate textures and I can do all of this via the script.

But where I'm stuck is with how I can generate X number of "Dust/Barren" planets with X number of generated textures with different seeds.

What I want to do is this:
* for each planet in the level do the following:
  - create a planet game object
  - access the "Dust/Barren" SGO, choose a random seed, generate the texture
  - assign texture to the planet's material/mesh render

The problem is that the SGO's generated texture is a shared texture and despite generating the texture with a different seed X times, it means that I'm only changing the same texture X times.  This means that every planet I create using the same SGO will look the same - effectively the last random seed that was used.

It appears the "proper" (?) way to do this is to call Duplicate on the Substance Graph object.  This means calling Duplicate, then generating the texture for each planet on the duplicate instance - X times.

The problem with that is that if I have a 100 planets, after generating the planets, if I view the SGO in Unity, it will have a 100 new Substance graph instances and removing them in the editor is a slow and tedious process.

I'm hoping that there's a better way to do this.  It doesn't make any sense that I would need to duplicate a Substance graph.  It smells of poor design.

I'm going to see if I can copy textures at runtime in Unity and perhaps then I can just use one SG to simply act as Texture Factory/Generator (which to me sounds like what it's supposed to be ...)


Edit, so copying textures seems like the way to go... I was mislead by the code/comments in the asset that I'm rewriting as the original author was waiting for the Duplicate method to be released so that it could support multiple instances.

Doesn't seem to be a need for any duplication, as I can just generate the textures, copy them and set them to the material and move on to the next planet.