Change material and animation from a prefab in runtime before instantiating.

My only doubt is accessing the prefab properties in resources, (if that’s the case), so when i run the thing it spawns doing the animation i want as “layer default state” and the material selected visible.

I write this because i could not find anything else any other place.
Hope someone can help me out.
Second pics shows animator with different layers, read those layers can be moved via code so the first at the top is the one launching the default state. Haven’t found it yet.

@punixer, do you have some overriding reason you cannot do all that after you instantiate?

Because if you edit the prefab at run time, to my knowledge, you will alter the prefab permanently - that is, any changes will stick with the prefab even after you stop running the game, and every instance of the prefab will take on the new properties you apply.

In other words, the only way to apply unique properties to instances of a prefab is to apply them to instances - and that should sound redundant! Any changes you apply you might as well apply in the editor.

Finally, public properties of script components attached to prefabs that reference other object aren’t retained in prefabs anyway - you have to assign those at runtime after you instantiate.

Hi @streeetwalker and thanks for the fast reply.
I’m quite noob at coding, so i dont understand override too much. I make many instances for the prefab.

The option i’m doing is put a small script on the prefab checking the currentMaterial of another static script in which i loaded the materials dragging them and then assign through that script to the current prefab before instantiating. So instead of instantiate → set material. (which consumes crazy memory), i just set it in the prefab. Maybe both are the same efficient-wise. No idea.
And i guess i’ll try the same with runanimatorcontroller for the animations.
Thanks again.