Search Unity

AssetPreview.GetAssetPreview always return null

Discussion in 'Scripting' started by acropole, Dec 25, 2013.

  1. acropole

    acropole

    Joined:
    Aug 13, 2009
    Posts:
    171
    Hi,

    As the title says, AssetPreview.GetAssetPreview always return null. Why ?

    Code (csharp):
    1.             if (evt.type == EventType.DragPerform)
    2.             {
    3.                 DragAndDrop.AcceptDrag ();
    4.              
    5.                 foreach (UnityEngine.Object o in DragAndDrop.objectReferences)
    6.                 {
    7.                     GameObject go = o as GameObject;
    8.                     if (go)
    9.                     {
    10.                         Brick brick = go.GetComponent<Brick>();
    11.                         if (brick)
    12.                         {
    13.                             if (!Bricks.Contains(brick))
    14.                             {
    15.                                 Texture2D tex = AssetPreview.GetAssetPreview(brick); //<------------------------------
    16.  
    17. //                              while (tex == null) {}
    18.  
    19. //                              tex.Resize(64, 64);
    20.                                 AssetPreviews.Add(brick, tex);
    21.  
    22.                                 Debug.Log(brick.name + " dragged");
    23.                             } else Debug.LogError(o.name + " already added");
    24.                         } else Debug.LogError("Only Bricks can be added");
    25.                     } else Debug.LogError("Only GameObjects can be added");
    26.                 }
    27.             }
    28.  
     
  2. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    I can't see from your code anywhere in there that prove that this specific asset actually exist as a file inside the Assets folder.
    Even worst, I doubt you could get the preview of a Component, as you cannot serialized a component individually.
     
  3. acropole

    acropole

    Joined:
    Aug 13, 2009
    Posts:
    171
    The object exists as it's dragged from the project view.
    And it don't even works with component's gameobject, renderer, meshfilter, material, object or anything related and existing in this prefab I tried.
     
  4. acropole

    acropole

    Joined:
    Aug 13, 2009
    Posts:
    171
    Now I do this in the OnInspectorGUI and it works fine :

    GUIContent content = new GUIContent(AssetPreview.GetAssetPreview(brick.gameObject));