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

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:
    576
    Also commands to remember AssetDb.SaveAssets() and EditorUtility.SetDirty(obj)
     
    Zinov likes this.