Prefabs losing Material connections after re-opening scenes. Bug?

Hello there!

I keep encountering a certain problem:

I am creating small animated prefabs of collections of about 10-15 game objects for re-use in scenes. These prefabs usually contain ~10secs of keyframed meshes, particles, skinned meshes, material-animations, etc (nothing out of the ordinary).

Now, sometimes those prefabs just happen to lose some of their material connections.

It usually happens after I re-open the scenes where the prefabs are instantiated. They then show up partially pink (the missing-material-pink) and I have to re-assign the materials by hand and hit apply. It happens without warning (theres no sign that the prefabs or their instances are damaged while I am working on them). I wasn't able to isolate the problem further than that (will post updates when I find out more!).

Any idea what could be the problem here? Some known issues with the animation editor or something that I overlooked?

Oh, and I am using Unity Pro 3.10f4 on Win-7 x64.

Thanks!


UPDATE:

With the suggestion of Mike, I watched the problem further. Though I'm still not able to recreate it step by step, I'm pretty sure it has something to do with the material instances.

Usually when a material that is shared by different objects in a scene is animated on single objects, Unity creates an instance of this material the moment the animation starts playing. Also, when the animation stops again or when you stop animating in the animation editor the object is re-assigned its original material and everything is fine.

Now, I noticed that sometimes during the process of animation, I seem to end up with the instanced materials left on the object after stopping animation. It goes hand in hand with left-over changes in other animated properties like transform. When I accidentally apply those changes to the prefab, it is not able to find this material instance, and hence appears with the pink missing material on scene-reload or on instancing.

Anyone able to confirm this or am I misinterpreting things?

If you're manipulating the renderer.material property of a prefab, it'll cause the prefab to create an instance of the material and assign that as the actual material - the issue is that when you reload the scene, that instance will be long gone

Try animating the renderer.sharedMaterial property instead - that one is the one you should always be using when manipulating things at editor time

Ok, now I managed to replicate at least one way this error appears:

  1. create a random mesh (game object with mesh renderer component, i.e. sphere) with a random custom material
  2. parent it to a new game object and add an animation component and an animation clip to this parent
  3. convert the two into a prefab
  4. add a random material animation to the object (i just animated an alpha-fade on an opaque object, so there's no visible change)
  5. make sure that the animation editor is still in record mode and hit Ctrl+D on the object to duplicate it (loses the prefab connection, but never mind that for now). The new game object now has only an instance of the material assigned
  6. hit apply on the prefab, reopen the scene and voilinstance material lost!

alt text

There have to be other ways too though. I'm pretty sure that I also encountered it without the above steps. So I'm not sure how helpful this is in your cases. I guess I'll now try to avoid this action as well as check my prefabs for left-over material instances before I close the scenes.

If you come across other ways to create this effect, I'd be great if you could post them here as well so we know what to look out for!

Thank you, vv

Hello,

This seems to be what is going on with mine except mine became pink when I switched to the new Macbook Pro Retina Display. Everything…and I mean everything went pink. It does not matter if they share the same materials or not.

To go through hundreds beyond hundreds and fix them seems well very time consuming…as does spending 100+ hours redoing the scene from scratch.

Anyone have any advice. I’m thinking somehow the connection of the Materials go lost in the migration…humm

I brought the materials folder and so forth over to the Project. Even when I do take one of the materials and drag it onto one of the objects…it goes white instead of taking on the created material.

and to add more to this mayhem, the scripts did not migrate over, or they did and I’ve no idea where they all went.