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. Let us know your feedback about the Global Illumination changes in the 2023.2 beta.
    Dismiss Notice
  3. Dismiss Notice

Building Asset Bundles causes compile errors if your scripts use System.IO.File on OSX

Discussion in 'Unity 5 Pre-order Beta' started by DanSuperGP, Jan 14, 2015.

  1. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    I've already submitted the bug for this (Case 663387) , but I figured I'd report it here as well because I also found a work around that lets you get back to work afterwards.

    This is a bizarre one that was driving me crazy, but I've figured out a simple way to reproduce it and sent in a simple repro project.

    Essentially, if you build asset bundles using the new asset bundle tagging system and you have any scripts which use System.IO.File, you will get a compile error after the next time you compile. Like this...

    Assets/Scripts/ReadCoffeeIpsum.cs(39,55): error CS0117: `System.IO.File' does not contain a definition for `ReadAllText'

    Apparently somehow building asset bundles breaks Unity's access to System.IO (or at least System.IO.File)

    The only way I've found to clear this compile error is to close Unity and delete the Library folder from the project. Which... is rather onerous if you have a large project.

    Lets hope they get this one fixed right away.
     
  2. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    Also, I don't know if this also happens on Windows, since I've only tested it on OSX.
     
  3. Deleted User

    Deleted User

    Guest

    Bug fixed in the coming b22. It's because building AssetBundle changes the build target but not restore it.

    In your case, you build AssetBundle with target platform WebPlayer, then the target will be changed to web player. You can check BuildSettings panel for it. As web player for security issue, file operations are not allowed. This is why you get the compiling error.
     
    DanSuperGP likes this.
  4. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    Oh, that makes sense. I just copied down the script quickly from the talk at Unite 2014... I don't think I ever looked at the script reference for BuildPipeline.BuildAssetBundles to realize that the target platform was an argument with a default.

    I guess I just assumed it would build the asset bundles for whichever target you had selected in Build Settings.

    I'll be adjusting that code now.