Search Unity

Mesh 'type mismatch' in inspector for prefab

Discussion in 'Editor & General Support' started by andymads, Sep 17, 2012.

  1. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Just wondering why I'm getting 'Type mismatch' in the inspector for the Mesh field of a Mesh Filter on a prefab? See image below.

    This is for my own procedural mesh (a sprite).

    The preview is being drawn correctly so the mesh at this point must exist.

    When the prefab is instantiated in a scene the Mesh field shows the little mesh icon.


    $Screen Shot 2012-09-17 at 08.51.35.png
     
  2. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Any comments?
     
  3. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    File a bug. :)

    Make sure to attach the script.
     
  4. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
  5. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    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
     
    sophia_wjw and Hypnotoad0 like this.
  6. Ben Blaut

    Ben Blaut

    Joined:
    May 15, 2012
    Posts:
    27
    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()"
     
  7. misher

    misher

    Joined:
    Apr 22, 2016
    Posts:
    19
    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".
     
  8. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    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.



    Help.
     
  9. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    at least it happens if you changed your public variable type in the script.. so just assign the reference again.

    is your reference object using Animator or Animation?
     
    renman3000 likes this.
  10. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699

    UPDATE:
    I just re-entered the variable as you suggested and it appears normal!! Yeh.





    ---- original post.
    Forgive me if my understanding is off....

    I dragged a group of sprites into the scene, making the animation. This creates the Animator and Animation.

    I see no reference to Stop() or Play() via the Animator, but I do via the Animation. However, Animation, posts the "Type mismatch".

    ??
     
  11. palakvasoya

    palakvasoya

    Joined:
    Aug 21, 2017
    Posts:
    3
  12. Deleted User

    Deleted User

    Guest

    I have the same problem. When I set an Object to ScriptableObject, getting type mismatch from Object. How to handle this issue ?