Save and apply in-game modifications to Material Instance?

I am writing a blueprint “game” that allows the user to play with scalar parameters of a material instance via a umg ui. I can modify a material instance at runtime… I would like to save those new scalar values and apply them to the material instance once the game is exited. I don’t want that info to only live with a saved game but rather I want it to actually propagate to the material instance itself. Is this possible via blueprint alone?

Use case: Right now I am using set scalar parameter (target is mesh component) and retrieving the slider value from the umg ui I created. If I change the roughness of a material all the way to zero… and close the game… I want the edited material instance to retain that new roughness value of zero.

Also (side note) I have read the ue4 documentation about creating a dynamic material instance in order to modify at run-time. While this does work…I have found that I do not need to do so. I can simply set scalar parameter on the material of a mesh component without actually creating a dynamic material instance. Is this process happening automatically? Or do both methods yield the same result?

No word on this one? Just to clarify…

Is it possible to save modified parameters from a dynamic material instance and then apply them to the original material instance via blueprint after the game is exited?

I would save the parameters out to a file in some arbitrary format, then have a function that loads the parameters from said format into a dynamic material instance.

Sure, this works for saving and loading dynamic materials. But i want to pass those stored parameters from a saved game object to a material instance constant that already exists in the project. Basically pull info from the game and actually apply it to a uasset after game exit.

1 Like

What is the use case for this? Uassets don’t exist after a game is packaged.

I want to launch a game that allows the player to customize a dynamic material instance. Then upon save I want to store those parameters in a save game object. But… this doesn’t change the material instance itself… so if I wanted to use this as a previs tool… all modifications would live with the game but I need them to propagate to the material that the dynamic material instance was created from. Is there a way to take the save game object data and pass it to a material .uasset?

Agreed. It doesnt sound like I can do what I want to do with bp since I need to do one of the following

  1. modify a material instance constant without making a dynamic version that is lost after game closes.
  2. transfer info from the dynamic material instance to a material instance constant after game close.

I’d say you have two routes here:

  1. Make an actor that autoloads the parameters from a save file into the dynamic material instance of your choice in it’s constructor script.
  2. Extend the Material Instance class in C++ to autoload from a save file, achieving the above but in it’s own new class.

I’d go with 1

This is kind of exactly what dynamic material instances are for. They are a template that you can modify parameters for at runtime

well you can do it fine with BP, you just need to make the BP logic to save and read from files. it will read whatevers in the file when the game starts up

do this:

  1. player starts game
  2. dynamic material instance is created
  3. player closes game or hits save
  4. dynamic material instance variables are stored persistently via https://docs.unrealengine.com/latest/INT/Gameplay/SaveGame/Blueprints/index.html
  5. player starts game
  6. dynamic material instance vars are loaded if present
  7. you have persistence :slight_smile:

I think I am not articulating my problem well enough. I know how to save and load these parameters… which means in game persistence. However, I want the actual material source to be modified after run-time.Let me explain.

  1. I run the game…
  2. The bp creates a dynamic material instance of " M_Material_001"
  3. Player modifies the parameters.
  4. Player closes game
  5. M_Material_001 somehow inherits the modified parameters from the dynamic material instance.

This is not a problem related to game persistence. It is a basically trying to recreate the functionality of the material instance editor inside a game.

Essentially I am trying to propagate modified material parameters from the dynamic material instance (created at runtime) back to the original material instance from which the dynamic one was created.