Is it possible to store on disk instantiated materials?

Hello

My game has a huge character creator, and for that I instantiate materials so the player can change the color of the clothing and not fuck up the original materials. I’m trying to make a variant of this character creator for me to create npcs, however, when I try to make the prefabs, all the materials get lost (because they are instances of the real materials)

Is there any way I could create a new material at runtime and have it stored on disk so I don’t lose the materials when creating a prefab?

I suppose you could write the texture to a file but a better way would be to log all the changes to the material and then apply it at runtime.

Changing material settings is just another piece of data, no different than choosing to wear Shirt #1 or Shirt #2, so all the same approaches used for saving your created character apply. Good tutorials for making character controllers should also have a way to save the data, so look around for those.

These things (character customization, inventories, shop systems) are fairly tricky hairy beasts, definitely deep in advanced coding territory. They contain elements of:

  • a database of items that you may possibly possess / equip
  • a database of the items that you actually possess / equip currently
  • perhaps another database of your “storage” area at home base?
  • persistence of this information to storage between game runs
  • presentation of the inventory to the user (may have to scale and grow, overlay parts, clothing, etc)
  • interaction with items in the inventory or on the character or in the home base storage area
  • interaction with the world to get items in and out
  • dependence on asset definition (images, etc.) for presentation

Just the design choices of an inventory system can have a lot of complicating confounding issues, such as:

  • can you have multiple items? Is there a limit?
  • if there is an item limit, what is it? Total count? Weight? Size? Something else?
  • are those items shown individually or do they stack?
  • are coins / gems stacked but other stuff isn’t stacked?
  • do items have detailed data shown (durability, rarity, damage, etc.)?
  • can users combine items to make new items? How? Limits? Results? Messages of success/failure?
  • can users substantially modify items with other things like spells, gems, sockets, etc.?
  • does a worn-out item (shovel) become something else (like a stick) when the item wears out fully?
  • etc.

Your best bet is probably to write down exactly what you want feature-wise. It may be useful to get very familiar with an existing game so you have an actual example of each feature in action.

Once you have decided a baseline design, fully work through two or three different inventory tutorials on Youtube, perhaps even for the game example you have chosen above.

Or… do like I like to do: just jump in and make it up as you go. It is SOFT-ware after all… evolve it as you go! :slight_smile:

Breaking down a large problem such as inventory:

https://discussions.unity.com/t/826141/4

I feel like the question was not understand.

I can change the properties of the material as I want at runtime due to my character creation system. However the material is not the [true] material, but rather an instance of that material, so whenever I modify the instanced material (like changing color for example) I don’t change the color of the base material.

Now, I want to use this system to create NPCs, as in, using all the system speed and utilities, but storing the characters as a prefab. However, due to the materials being instances they won’t get saved. What Im asking is, if there is any way to save the instanciated material as a new material on disk.

I don’t want to change the properties of the base material, I’m just asking for creating a new material at runtime, not saving and loading data either.

Yes:

  • store a reference to the original material asset (in whatever form you want, the name, a number from a hard-coded list, your choice)

  • store all changes you make to that original material asset

on load:

  • get the right material

  • instance it again

  • apply the changes

  • use it

Well I guess there is no solution to my problem.

I don’t want to load the properties, I just want to save a material at runtime. Create a new material asset so I can use it for NPCS, not just keep instantiating materials and changing properties at runtime based on loading stuff.

This is not something for player load, but for editor use, to create materials to facilitate NPC creation ,as all npcs in my game will be humans wearing clothes, so I would rather have each with their own material, than gets shared between same clothing, than having 500 materials instanced at runtime running code to replace their values.