Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Path separator characters have changed.

Discussion in '2018.3 Beta' started by Sluggy, Dec 6, 2018.

  1. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    So I recently started migrating my codebase from 2017.4 to 2018.3 when I came across some issues with a few custom editor tools.

    It appears that using methods of System.IO.Path now use the proper directory separator character for windows, i.e. '\\' instead of '/'. This is probably a good thing for the sake of consistency but it's causing a lot of issues with custom editors that use this class when handling file directories and building complex directory strings by combing use of by Path and AssetDatabase.

    Long-story-short, this is probably going to break a lot of editor tools and make it extremely cumbersome to fix them without lots of people writing duplicate libraries to handle platform-specific directory chaining.

    Small Update: ProBuilder's Export Mesh tool is now broken.
     
    Last edited: Dec 6, 2018
  2. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    So the number of tools and assets I'm using that can't properly save files was getting somewhat frustrating so I decided to file a bug report (1107104) in the hopes that this will at least get some attention. I'm doubtful that it will change but it would be nice to know that someone is at least aware of this issue and considering it.
     
  3. mkderoy

    mkderoy

    Unity Technologies

    Joined:
    Oct 25, 2016
    Posts:
    22
    Did you happen to switch from .Net 3.5 to .Net 4.6 when you upgraded? .Net 4.6 uses the platform's default path separator, whereas .Net 3.5 would always uses forward slashes.
     
  4. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    My current project is firmly stuck in 2017 using .Net 3.5 due to compatibility issues.

    However, in this case I had started a brand new project in 2018.3b10, copied all of my libraries and commonly used asset store packages over, and slowly and methodically started fixing errors and bugs until the code base was up to date with 2018.3 standards. I deliberately made sure the project was set to use 4.6 so that I would know if there were any issues that would crop up - I guess I found one ;)

    Largely the issue seems to stem from many libraries assuming that all of the path directories within the project directory would have the traditional '/' path separator and then using something like String.Split() to manually parse them. As I mentioned, it makes sense that you'd want the proper directory separator for the OS you are on, but it's incompatible with the internal directory separator that Unity's editor uses within the project space itself. The way it is now, you'll be seeing a lot of devs having to write code that needs check both the operating system as well as the directory path itself and determing which set of separators to use, and then constantly convert back and forth depending on whether or not they are interacting through Unity's Resources/AssetDatabase system or the .Net File/Path system. It gets even worse if it's something for the asset store that needs to maintain backwards compatibility as they will also have to check the Unity version and .Net backend being used (if that's even possible in the API).

    Overall I see a lot of headaches and thick layers of file abstraction libraries in the future for all projects and asset store packages if this remains this way.
     
  5. This is why you should not assume the separator but ask the environment what is it...
    The Path.DirectorySeparatorChar isn't particularly newcomer in C#.
     
    LeoFeitosa likes this.
  6. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    960
    I'd agree, but Unity's internal file system is out of my hands there ;) I'm sure there is a reason they went with a forward slash and I suspect it was for the sake of making cross-platform development easier.
     
  7. mkderoy

    mkderoy

    Unity Technologies

    Joined:
    Oct 25, 2016
    Posts:
    22
    Thanks for filing the bug and making us aware of it, we'll be looking into it soon.