Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Add file to Resources before building executable

Discussion in 'Editor & General Support' started by Zinov, Apr 17, 2016.

  1. Zinov

    Zinov

    Joined:
    Jul 20, 2015
    Posts:
    38
    Hello. I want to autogenerate some files before embedding them in build. I wrote a system residing on top of BuildPipeline.BuildPlayer call, but unfortunately, all my files generated before calling this function does not have any effect on actual build.

    For example, before calling BuildPipline.BuildPlayer, I populate the text file and add it to Resources folder. However, when I try to read it with Resources.Load<TextAsset> the error is throw that the file doesn't exist.

    So, my question is how can I effectively implement PreBuild step in Unity?
     
  2. Zinov

    Zinov

    Joined:
    Jul 20, 2015
    Posts:
    38
    Oh, I solved the problem just a second ago. The key was to add AssetsDatabase.Refresh() so my generated text file got reimported before I called the actual build function.
     
  3. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    543
    Also commands to remember AssetDb.SaveAssets() and EditorUtility.SetDirty(obj)
     
    Zinov likes this.
unityunity