Search Unity

Copy Avatar source in OnPreprocessModel

Discussion in 'Scripting' started by jrhee, Aug 5, 2016.

  1. jrhee

    jrhee

    Joined:
    Dec 5, 2013
    Posts:
    74
    Hi,

    I'm trying to automate our animation import process, and as part of that I'd like to copy my avatar definition from an existing source. Here's a piece of the code in my AssetPostprocessor class:

    Code (CSharp):
    1.     void OnPreprocessModel()
    2.     {
    3.         if (ShouldProcessAvatar(assetPath))
    4.         {
    5.             ModelImporter importer = assetImporter as ModelImporter;
    6.             var avatarAsset = AssetDatabase.LoadAssetAtPath<Avatar>(avatarPath);
    7.             importer.sourceAvatar = avatarAsset;
    8.         }
    9.     }
    The code runs fine and I see the source update in the inspector, but the "Update" button always appears. It doesn't seem like the change is getting committed properly. Is there an additional step I'd need to take here?

    upload_2016-8-5_15-3-0.png

    Thanks!
    John
     
  2. ionside

    ionside

    Joined:
    Apr 7, 2011
    Posts:
    43
    Hi, did this get figured out? I'm having a similar problem.
     
  3. ionside

    ionside

    Joined:
    Apr 7, 2011
    Posts:
    43
    Ohhhh, bug in 5.5.
     
  4. nocanwin

    nocanwin

    Joined:
    May 7, 2009
    Posts:
    176
    happens in 5.6. An easy fix is to only set the avatar when it's null.