- Home /
Can Material Property Blocks be serialized?
I'm procedurally generating a group of meshes with varying properties using Graphics.DrawMesh().
Since I don't what the result to re-randomized every time I press Play, I'm storing the variables that modify each mesh instance in a serialized array of structs, then passing the stored data from that array into Graphics.DrawMesh() whenever it's called in Update().
This seems to work for everything except Material Property Blocks. If I create a MPB for each mesh instance, set properties on it, and store it in my properties array before hitting Play, that data seems to be lost on Play.
My workaround for now is to just store the material properties I want directly (as Float, Color, Texture2D variables, etc.) in my properties array, then create a new Material Property Block and populate it with those variables every frame for every call of Graphics.DrawMesh().
Is this the best approach, or is there a way to get those premade Material Property Blocks to persist?
Answer by msaccone · Sep 25, 2017 at 06:47 AM
This may be too simple a fix for what you're attempting, but have you tried specifying the seed at start instead of storing the properties?