I guess this suddenly belongs in answers but I’ll include it here regardless.
Essentially that is because you’re referencing a mesh thats not an asset. Whenever you do new Mesh() you create a mesh in the scene. Its only if you give it to the asset database that it becomes an asset. Scene objects can be cleaned up by the editor at a number of times. This is handled just fine by the scene, but it doesn’t work properly with the prefab system. Leaving a stray pseudo released mesh on the prefab.
A check like this will tell you if its a good idea to create a nonserialized scene mesh in your script in the editor.
#if UNITY_EDITOR
if (!UnityEditor.EditorUtility.IsPersistent(this)) #endif
I’ve been looking for this answer in my dreams for a few weeks now. I was having the same problem, but with animation clips added to a prefab. This really needs to be added to documentation or something. Or if it’s there, it needs to be made more explicit. I was under the assumption that Unity handled its asset database automatically when you do a “new Anything()”
I have the same problem with Sprites created at runtime using images(textures) loaded from disk (or downloaded).
In inspector I can see “type mismatch” for sprites objects. This is only visual inspector bug i suppose, because when I click on select asset point I can see the current sprite preview correctly at the bottom of the select sprite window, there just no reference to the assed database (no asset exists in project view). Unity may fix this visual bug simply replacing “type mismatch” with something more appropriate, ex: “runtime asset”.
Hi there,
I have a 2D sprite animation, which I created in scene.
I want to control when it starts and stops. I thought I needed to do this via the Animator component, but it seems I need to do it via the Animation component.
Here in lyes my problem.
When I add a “public Animation anim” variable to my script, in the inspector, I get a “Type mismatch”, in the respective field.
So, all I need to know is how I can control an animation, to stop and start.