- Home /
(Unity Serializer) Materials doesn't load when loading a prefab at runtime.
I have saved(Using WhyDoIdiot Serializer) a scene placing prefabs at some position. Later I deleted some Prefabs and I want those prefabs to be instantiated at runtime by loading the scene using serializer. I could get them to load but the materials doesn't load up even though I have 'store materials' added to them. How to load these materials? :(
I am having the same issue,
IEnumerator SaveCraft() {
LevelSerializer.DontCollect();
byte[] data = LevelSerializer.SaveObjectTree(craft);
yield return new WaitForEndOfFrame();
LevelSerializer.Collect();
var f = File.Create(Application.dataPath + "/Craft/"+craftName+".CRAFT");
f.Write(data,0,data.Length);
yield return null;
f.Close();
yield return new WaitForEndOfFrame();
}
IEnumerator LoadCraft(string fileName) {
var f = File.Open(Application.dataPath + "/Craft/" + fileName, File$$anonymous$$ode.Open);
var data = new byte[f.Length];
f.Read(data, 0, (int)f.Length);
f.Close();
var complete = false;
LevelLoader loader = null;
LevelSerializer.DontCollect();
LevelSerializer.LoadObjectTree (data, (usedLevelLoader)=>{
complete = true;
loader = usedLevelLoader;
LevelSerializer.Collect();
});
while(!complete){
yield return null;
}
craft = GameObject.Instantiate(loader.Last.gameObject, Vector3.zero , Quaternion.identity) as GameObject;
craftName = craft.name;
InitializeParts ();
building = true;
}
Answer by Cherno · Aug 28, 2014 at 09:29 AM
If you are using custom shaders, you will have to add their parameters manually in the material serialization script.
Your answer
![](https://koobas.hobune.stream/wayback/20220613092915im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is it possible to load an audio file at runtime? 2 Answers
Loadimage Texture at runtime 1 Answer
How to change a specific material of an object ? 0 Answers
Export objects to a .3DS file at runtime 1 Answer
load c# script from server 4 Answers