Search Unity

Txt file in resources is read on mac build but is not read on windows build

Discussion in 'Editor & General Support' started by Wawwaa, Jan 13, 2019.

  1. Wawwaa

    Wawwaa

    Joined:
    Sep 30, 2017
    Posts:
    165
    I have a txt file in Resources folder which I load as TextAsset at runtime. I use this to instantiate objects at certain positions with certain rotations. Everything works great on editor and on build on mac. But, on windows build, the file is not read, so those objects are not instantiated. Has anyone had this problem? How did you solve the issue? I am using Unity2018.3.
     
  2. - please try to post in relevant forum, General Discussion is not it
    - my vague guess would be some kind of txt-incompatibility (line endings?)
     
    angrypenguin likes this.
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    You are going to have to give me more details then that.

    The file is not read could be a bunch of things. Here is a list to check.
    • The file does not exist
    • The file does not open as text
    • The file does not parse correctly
    • Objects are not created as a result of parsing the file
    Put in a few Debug statements and do a debug build. It shouldn't take you long to figure out which one is happening.
     
    angrypenguin likes this.
  4. Wawwaa

    Wawwaa

    Joined:
    Sep 30, 2017
    Posts:
    165
    Thanks for the warning. Which is the relevant forum?

    Update: I found out that file is reading but the actual problem is instantiating from Resources folder. Mac builds run ok, but windows build does not load objects. So, why is it not instantiating? I make windows build on mac.
     
  5. Either "Scripting" or "Editor and General Support". But please don't duplicate your thread, report your initial post instead and ask the moderators to move it.

    It's a very vague question. We don't know, we can't see it. Try to Debug.Log things and/or see the player logs of the game on the windows machine for more info.
    https://docs.unity3d.com/Manual/LogFiles.html
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    If I remember correctly, the direction of the slashes in the string when you call Resources.Load is an issue. Give this a shot.
     
    Lurking-Ninja likes this.
  7. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    Unless it's covered by one of the more specific forums, "Scripting" is a safe bet.

    Note that the description on the General forum specifically says it's not for support.
     
  8. Wawwaa

    Wawwaa

    Joined:
    Sep 30, 2017
    Posts:
    165
  9. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    736
    Eric5h5 to the rescue again.
    https://answers.unity.com/questions/168337/pathname-slashbackslash.html

    I dev on windows and just use forward slashes.
    I expect Unity is doing something in there.
    The problem is if you try to use back slashes on non-windows.
     
  10. Actually windows accepts the / too in path. At least Windows 10 does, I don't remember if older ones do.

    cd / will take you to the root of the active drive
    on the windows main disk: cd Users/<username>/Downloads will take you to the Downloads folder in the cmd app or in the Explorer likewise.

    Since I worked a lot in multi-OS environment I developed the habit to use the path-separator constants anyway.
     
  11. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    736
    Just for fun I found this conversation
    https://bytes.com/topic/python/answ...-start-accepting-forward-slash-path-separator

    tldr:
     
    Last edited: Jan 14, 2019