Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using links (Sym Hard) to create a common folder for all Unity Projects

Discussion in 'Scripting' started by Adam-Buckner, Sep 14, 2011.

  1. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    It all started here: http://forum.unity3d.com/threads/103967-How-to-earn-£12-000-in-one-year-from-game-development/page9





    -

    What I'm discovering is that on OSX, Symbolic Links are not recognized by Unity and they appear as simple aliases in the finder.

    This means that to do this on the Mac one must use hard links, which normally only point to a file, not a directory.

    There is this thread:
    http://stackoverflow.com/questions/80875/

    Which has code that needs compiling to do it.

    There is some worry that this could muck up TimeMachine. Currently it seems that TimeMachine treats any hard links that are not its own as new files, so all linked files will be duplicated in time machine. I assume that as they are linked they will be restored properly overwriting themselves as they come down.
     
  2. justinlloyd

    justinlloyd

    Joined:
    Aug 5, 2010
    Posts:
    1,680
    I am in the middle of setting up ten demo machines with our current build of the software so I am wrapped up, once I get a few moments I will fire up the Mac and tell you the exact command you need to create a symlink to a directory. Damn Mac users. :)
     
  3. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
  4. zyndro

    zyndro

    Joined:
    Oct 19, 2010
    Posts:
    78
    bookmarked !!!
    thank you !!
     
  5. joshimoo

    joshimoo

    Joined:
    Jun 23, 2011
    Posts:
    266
    If you don't find a solution for a link on the mac, you could also try mounting the the directory inside of your Project.
    This gave me an Idea for a quick editor scripts, will post later, I am going to bed now.
     
  6. rstehwien

    rstehwien

    Joined:
    Dec 30, 2007
    Posts:
    101
    You could also use git and git submodules to version control your shared projects in one git repository and use as a submodule in another..... you don't even need pro to version control scripts without too much trouble.
     
  7. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    rstehwien: I've taken a few frontal assaults on GIT and I have an account on GitHub, but I have yet to figure out how to integrate this into a Unity project.
     
  8. rstehwien

    rstehwien

    Joined:
    Dec 30, 2007
    Posts:
    101
    You can use git locally... one of the advantages of git is you don't need a server like you do with subverison. GitHub (where I have many projects myself) is useful for sharing projects with the public (free) or a team (pay... unless you want it open source). I use git on my local machine for projects that will never be put on a server.... just drives me crazy to not use source code control.

    Here is a good book:
    http://progit.org/book/

    Setup instructions:
    http://progit.org/book/ch1-4.html

    Section on submodules:
    http://progit.org/book/ch6-6.html


    If I have some time later... I'll get some unity specific instructions ready for using git. All my unity projects have been throw away... but I'm rapidly approaching real projects that will require the use of git. I have used git for my professional work outside of unity so I know it can work.
     
    Last edited: Sep 21, 2011
  9. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
  10. rstehwien

    rstehwien

    Joined:
    Dec 30, 2007
    Posts:
    101
    I haven't had time to writeup instructions but here are two github projects I found (by the same person but there were others) that have instructions for using git submodules:

    https://github.com/MrJoy/UnityGUIExtensions
    https://github.com/MrJoy/UnityREPL

    Basically you do the following (the path to the module will vary and may even be local)

    GIT SETUP IN A UNITY-PRO PROJECT THAT IS NOT VERSIONED WITH GIT

    You must have External Version Control enabled to use these instructions. If not, please download the .unitypackage and use that.

    cd myproject/
    mkdir -p Assets/Editor/
    git clone git://github.com/MrJoy/UnityREPL.git Assets/Editor/UnityREPL
    git clone git://github.com/MrJoy/UnityGUIExtensions.git Assets/UnityGUIExtensions

    By setting up this way, you can track updates using “git pull”.


    GIT SETUP IN A UNITY-PRO PROJECT VERSIONED WITH GIT

    You must have External Version Control enabled to use these instructions. If not, please download the .unitypackage and use that.

    cd myproject/
    mkdir -p Assets/Editor
    git submodule add git://github.com/MrJoy/UnityREPL.git Assets/Editor/UnityREPL
    git submodule add git://github.com/MrJoy/UnityGUIExtensions.git Assets/UnityGUIExtensions
    git submodule init
    git submodule update


    LINKS
    Some links on setting up git in general.

    http://unity3d.com/support/documentation/Manual/ExternalVersionControlSystemSupport.html
    http://www.chrisdanielson.com/2011/06/04/unity3d-projects-version-control-git/
    http://raypendergraph.wikidot.com/using-git-with-unity3d
    http://forum.unity3d.com/threads/69609-Source-Control-w-Free-Unity-ignore-files-(Git-SVN-CVS)
    http://answers.unity3d.com/questions/topics/git.html
    http://progit.org/book/
    http://book.git-scm.com/
     
    Last edited: Sep 25, 2011
  11. justinlloyd

    justinlloyd

    Joined:
    Aug 5, 2010
    Posts:
    1,680
    Was asked to follow up on this. I had forgotten that Unity on Mac OS X for whatever reason won't see symlinks to directories. You have to create hardlinks to directories instead. Mac OS X won't let you do that by default, even though the underlying DFS supports it. It's how Time Machine works.

    I followed this guide from 2008 on how to put a hard link to a directory on your machine: http://osxbook.com/blog/2008/11/09/hfsdebug-40-and-new-hfs-features/

    Hard links are not for the faint of heart and can tie your file system in knots if you aren't used to them.

    If you don't want to use hard links, try instead a two way rsync or even Unison http://www.cis.upenn.edu/~bcpierce/unison/ which will do it for you.
     
  12. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Thanks, JustinLloyd!

    We really appreciate the professional help.
     
  13. spadesmaster

    spadesmaster

    Joined:
    Dec 29, 2010
    Posts:
    11
    The above link clearly shows the only way to create a hard link to a directory on the Mac is to write some custom code and build it. It specifically has numerous scary warnings about trashing your file system if you use this. No thanks!

    I can confirm that Unity 2.4 refuses to follow symlinks to directories on Mac OS X. It works fine on Windows machines. We have shared Editor, Plugins, and even various project-level Resources and Scripts directories. Works PERFECTLY on Windows (which is hard to make symlinks on).

    I will make some hard-links now, but this is hard and potentially dangerous. How do I report a bug on this and request it get addressed?

    Christopher
    DreamQuest Software
     
    Last edited: Oct 26, 2011
  14. justinlloyd

    justinlloyd

    Joined:
    Aug 5, 2010
    Posts:
    1,680
    Open Unity
    Select Help menu
    Select Report Bug

    Yeah, the Mac OS X solution is less than ideal, but it was the only way to fix it. I assume you mean 3.4 rather than 2.4. :) You can of course get around all of this nonsense by using version control on your source code, but it shouldn't have to be that way. :(
     
  15. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    What he said.

    TBH, I'm waiting to see how version control works in 3.5. This *may* make things easier. Not sure why Unity Mac doesn't support aliases (soft link) by default, as they are a system feature. Could be a base architecture issue. I know some of the features I'd like to see (nested prefabs for instance) are on the road map, bit require fundamental changes in the architecture of the editor. Perhaps windows links work as the windows editor is relatively new compared with the Mac? Report it. Let's see if we can get some mileage out of it.
     
    Last edited: Oct 27, 2011
  16. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,152
    is it still the same on Mac OS? how can i use symlinks on Mac?
     
  17. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,042
    On a Mac use :
    Code (csharp):
    1.  
    2. ln -s [source] [target]
    3.  
    So let's say I have a directory of shared assets located at:
    /Users/ZG/Projects/Unity/SharedAssets

    And I wanted a symbolic link to that in the folder:
    /Users/ZG/Projects/Unity/AwesomeGame/assets

    I would type:
    Code (csharp):
    1.  
    2. ln -s /Users/ZG/Projects/Unity/SharedAssets /Users/ZG/Projects/Unity/AwesomeGame/assets/SharedAssets
    3.  
    Important: It will create the link "SharedAssets" in that directory, so if you already have a folder or file with that name, it will be overwritten.

    Unity will throw a notice in the console saying essentially that you should be careful doing this. Which is good advice, if you delete/change any of the files in there, it will impact all your projects using that alias. (since there is only one set of files)
     
  18. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Be aware that Unity's support for symlinks has fluctuated somewhat due to concerns that you could really mess things up if you are not careful, especially on the mac.

    As of 4.2, symlinks are now supported on both the Mac and Windows platforms:
    http://unity3d.com/unity/whats-new/unity-4.2
     
  19. ThirdMotion

    ThirdMotion

    Joined:
    Jan 9, 2013
    Posts:
    1
    I just finished get this set up on my Mac; now, whenever Unity regains focus, it reimports every asset in the symlinked directories. The project is still small -- so it only takes 20 seconds -- but given how I bounce back and forth between Mono and Unity, even 20 seconds is intolerable. The assets are not changing; there are no "circular" symlinks; this only happens on Mac; Pcs are fine. Please help.

    Steve

    Edit: BTW, I just tried something; instead of linking to many (10 or so) directories, I just symlinked to the "parent-most" directory and the "always reimporting problem" went away. Although this is good news, it is NOT a solution. It is just a clue into how fix the bug -- please fix the bug. I should have the option of "symlinking"' any number of directories -- not just one.

    Edit2: I am now going to experiment with 2 symlinks and see what happens.

    Edit3: The problem occurs if I have 2 or more symlinked directories -- regardless of how many or few files are in those directories
     
    Last edited: Jul 28, 2013
  20. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    If you believe this is a bug, then please submit a bug report.

    I do not use, nor fully understand all of the ramifications of, sym-links. These are not limited to setting up the symlinks, circular links, confusing backup engines and potentially corrupting multiple projects at once by updating the shared folder(s).
     
  21. KyleStaves

    KyleStaves

    Joined:
    Nov 4, 2009
    Posts:
    821
    How do you guys get around the meta file limitations? Assuming

    Code (csharp):
    1.  
    2. Assets
    3. Assets/Shared/
    4. Assets/Shared/CoolComponent.cs
    5. Assets/Shared/CoolComponent.cs.meta
    6.  
    Sharing the entire "Shared" directory is easy a multitude of ways (sym-linking, git submodules, svn externals...) - easily sharing all of the non meta files while keeping the meta files backed up in the project specific repository without setting up each individual file as an external for each project has proven to be very difficult.

    Eventually we gave up and now just use a .dll for all of our 'library' code.
     
  22. Pi_3-14

    Pi_3-14

    Joined:
    May 9, 2012
    Posts:
    168
  23. tosi

    tosi

    Joined:
    Jul 5, 2012
    Posts:
    45
    I tried to use the symbol links to share the Asset and ProjectSettings folder between two projects, which are actually the same project, but with different build targets. The idea was not to wait several minutes every time I change the target. I created the symbol links with the app SymLinker. Opened the project and got an error in Unity editor telling me a temp file could not be opened:
    Internal compiler error. See the console log for more information. output was:error CS2011: Unable to open response file: Temp/UnityTempFile-29700b5aa20c2423ba9aa5bd00273061

    The file is there. I don't know what is causing the problem. Does anyone of you?
     
  24. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I can't speak to the specifics of using sym-links here, but if you are using the same project for different build targets, you should look into the cache server. This is specifically designed to handle the assets with different import settings between build targets.