Search Unity

Unity Post Processor Link Error

Discussion in 'Scripting' started by GabeF, Jun 30, 2014.

  1. GabeF

    GabeF

    Joined:
    Sep 28, 2012
    Posts:
    38
    Hi Guys,

    I've got some troubles with my scripts during the utilization of the assetPostProcessor. I can reproduce this all the time.

    This error occurs when I originally import the asset into unity. I trigger the OnPostprocessModel and get the following error:



    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. LightMapsManager.possibleToApplyLM (UnityEngine.Material sharedMat) (at Assets/Scripts/LightMaps/LightMapsManager.cs:206)
    3. LightMapsManager.InitializeShaders (System.Collections.Generic.List`1 objectnames, .LightMapGroupClass LMGC) (at Assets/Scripts/LightMaps/LightMapsManager.cs:150)
    4. LightMapsManager.InitializeAllShaders () (at Assets/Scripts/LightMaps/LightMapsManager.cs:219)
    5. AutoLoad.OnPostprocessModel (UnityEngine.GameObject g) (at Assets/Scripts/Editor/AutoLoad.cs:284)
    6. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
    7. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    8. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
    9. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    10. UnityEditor.AttributeHelper.InvokeMemberIfAvailable (System.Object target, System.String methodName, System.Object[] args) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/AttributeHelper.cs:246)
    11. UnityEditor.AssetPostprocessingInternal.PostprocessMesh (UnityEngine.GameObject gameObject) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/AssetPostprocessor.cs:182)
    12.  
    Now before importing to unity, I delete the Materials folder, because I want unity to apply some custom properties on the material import settings themselves that get derived from the functions supplied to the OnPostprocessGameObjectWithUserProperties

    The second time i import the model, with the materials folder already having been imported once, everything is fine and the script works.

    So my question is, at what point do the materials get linked up, and when can my scripts have access to those renderers?
     
  2. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    I don't know the exact sequence, but I guess your Asset post processor needs to look to see if the materials are present, and if not, you'll need to get your material post processor to look for the related mesh asset.