Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Asset labels not available during AssetPostprocessor

Discussion in 'Scripting' started by Dantus, May 18, 2011.

  1. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I am implementing a small post processor. I don't want that all models are going to be modified by the post processor. That's why I would like to perform the operations only if the model has a certain asset label. But it seems that the labels can not be access during the post processing. Is that correct?

    Code (csharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. public class TestPostprocessor : AssetPostprocessor {
    7.  
    8.     protected void OnPostprocessModel (GameObject model) {
    9.        
    10.         Debug.Log ("Postprocess");
    11.        
    12.             // Empty asset path, so it is not yet an asset?
    13.         Debug.Log ("Asset path: " + AssetDatabase.GetAssetPath (model));
    14.  
    15.         foreach (string label in AssetDatabase.GetLabels (model)) {
    16.             Debug.Log (label);
    17.         }
    18.     }
    19. }
    20.  
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    To my knowledge, thats correct yes. They are for in-editor filtering only and cease to exist afterwards.

    You would use naming schemes to do this kind of "filtering" similar on how you would do it for Import processors too
     
  3. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Thanks dreamora
     
  4. Rod-Green

    Rod-Green

    Joined:
    Apr 19, 2010
    Posts:
    51
    I'm not sure if this changed since Dreamora's post however you can get the labels if you query the assetImporter

    "AssetDatabase.GetLabels(assetImporter)"

    I ran into this issue and found that the GameObject wasn't setup with the labels however the assetImporter was.
     
    CoughE, pointcache and Mark-Davis like this.
  5. Mark-Davis

    Mark-Davis

    Joined:
    Jun 21, 2011
    Posts:
    156
    Worked as advertised. Thanks!