Search Unity

[5.6] "Non-Pro asset count incorrect" warning on AssetDatabase.Refresh

Discussion in 'Asset Database' started by JohannesMP, Jun 3, 2017.

  1. JohannesMP

    JohannesMP

    Joined:
    Nov 4, 2016
    Posts:
    21
    Overview

    I'm using a template system based on https://github.com/dimmpixeye/Unity3d-Project-Setup/tree/master/ProjectPref/Editor/CodeTemplates that parses and replaces certain keywords in newly created script assets.

    This is done with a UnityEditor.AssetModificationProcessor that modifies newly created scripts in OnWillCreateAsset and finally calls AssetDatabase.Refresh to force the scripts to be recompiled.

    However when Asset Serialization is set to 'Force Text' or 'Force Binary' I get the following warning whenever adding a new script (so when OnWillCreateAsset is called):


    Even more annoying, when saving changes to -any- script in MonoDevelop or Visual Studio, the warning pops up as well (although strangely without referencing any callstack at all):



    To Reproduce
    Using Unity 5.6.1f1 Personal (64Bit Windows)

    Here is a trivial example that just prepends a comment to any newly created scripts: https://gist.github.com/JohannesMP/74d2b5b58dc89aee03d8515c551943ac

    To reproduce, create an empty project, add an 'Editor' folder and place the script inside, then create a new C# Script anywhere.

    Note that this does not seem to happen when Asset Serialization is set to 'Mixed'. It only seems to happen when using either 'Force Text' or 'Force Binary'.


    Question
    I've submitted a bug report, but am posting here because I'm curious if any users could provide insight into what might cause this issue, and if I could avoid it.

    If I don't call AssetDatabase.Refresh after modifying the file, then the problem does not occur. However to my knowledge, if I don't call AssetDatabase.Refresh then changes to the file won't be loaded until the next recompile.

    Do I really need to call AssetDatabase.Refresh in the first place, or is there an alternative here?
     
    Last edited: Jun 3, 2017
  2. JohannesMP

    JohannesMP

    Joined:
    Nov 4, 2016
    Posts:
    21
    After some more digging, I am now able to answer my own question:


    In my use case I do indeed need to refresh the AssetDatabase, because without doing so unity will not be aware of the changes that were made to the templated script.

    For example, if the script is a MonoComponent, if the class name was modified by the AssetModificationProcessor, this can result in an error when trying to add a component, because (as far as unity is concerned) the filename does not match a class name:



    The workaround I discovered is that instead of calling AssetDatabase.Refresh(), I can use
    AssetDatabase.ImportAsset(assetPath) which forces a refresh for just that file without causing the "Non-pro asset count incorrect" error.
     
    A_Vrankie likes this.