Search Unity

c# script - Using a namespace from another Unity project

Discussion in 'Scripting' started by Quatum1000, Apr 6, 2020.

  1. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Hi everyone,

    I wrote some functions (MyTools namespace) I use for every project.
    Unfortunately I must copy the newest MyTools folder into all other projects. This is very ugly and prevent to edit the Tools by simple click on the function in VS.

    Would it possible to direct the using directive to another main project that contains this name space?
    using MyTools;

    So it doesn't matter where MyTools is located an every project use the same newest version.

    * In VS the Project Reference Manager (add project) want always a com or dll executable that does not work.
    * I used also system link, that works so far but when uploading to dropbox the link will deleted by dropbox. (DP is buggy in this case)

    An idea how to reference a name space to another unity project?
    Thank you.
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    No, the code has to be in your Unity project folder in some form to be used by your project, full stop. (You could look into compiling this into a DLL which you can put in your folder, but that adds complication and doesn't solve the problem of keeping your code updated.)

    You might look into putting these tools into a git repository which you can clone into all your project folders. This will be easy to keep your tools updated. This is actually preferable to always being updated everywhere automatically, because if you make changes based on needs for Project A which breaks functionality used in Project B, Project B can remain on the old version until you have time to get around to fixing said functionality, and B won't just be sitting there fully broken until the tool is fixed.
     
    Ryiah, lordofduct and Quatum1000 like this.
  3. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Thank you!
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    Another option I've been considering testing just to see how well it works is a symlink.

    Create a project folder for your MyTools somewhere in your file system, then create a folder in your project with a symlink to the project folder for MyTools. You can still git (or other vc) that folder, but not need to clone it to every project.

    Creating symlinks vary from OS to OS. But all 3 that Unity editor supports have it (win, mac, linux).
     
    Ryiah and Quatum1000 like this.
  5. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Yes, I tested this already but Dropbox has issued with symlinks. Dropbox smashed them. Al projects are located in a Dropbox folder but I never use git for some performance reasons.
     
  6. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    I just noticed you mention symlink in your OP. Sorry I missed that. And yeah, I can see how dropbox would do that... it doesn't know the symlink exists, since the entire point is that the symlink behaves like a normal system file hierarchy. I'm betting when it syncs it just clears out the directory and rebuilds it, thus deleting the symlink.

    What performance issues are you having with git?

    ...

    I will say I only recently moved to bringing my tool libs into my projects as source code files recently. In the past I had my own separate vs project that I compiled into dll's (StarManta mentioned this method in their post). I would then create a "build" batch file that I ran any time I updated the project and it would automatically compile and copy the dll's into any projects I was working on. But yeah, as StarManta mentioned, it required a bit of extra work. It also makes debugging them really annoying.
     
    Last edited: Apr 6, 2020
    Quatum1000 likes this.
  7. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    From my location its too slow. sometimes git takes up to 30-40seconds up a single files 2K with all the dependencies. Droptox takes some seconds.

    For sure it's possible to wirte a small c# script in the current project, will copy the folder containing the tool files from anywhere into the project itself. Not sure if unity will up the assetdatabase in this case.. but I will see :)
     
    Last edited: Apr 6, 2020
  8. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    Oh, you mean the remote git host was slow.

    Who did you use? Have you tried another host? Or considered hosting your own?

    Personally what I do is I have a home server here at my house (it's my home file server, plex, and other stuff). I push to that when I do commits (note git doesn't require a remote, it's just useful for back-up purposes). Then every monday night at 3am I have a script that runs on the server which zips all my git repositories up and places them in my google drive for remote backup. This way even if my house burned down I lose at most the last 7 days of work (I could do more frequent uploads, I just picked weekly to avoid chewing through all my bandwidth).

    This way all my commits/pushes were generally fast (they're all local to my network). And I offload my remote back up to a middle of the night task that occurs on a machine I don't use as my work machine. It doesn't matter how slow it is.

    You may consider a local server a bit expensive, but not really. My server is a cheap-o dell server, I think I spent 400 dollars on it, which includes the 10TB of storage I bought for it 3 or so years ago. Heck you could do it with a raspberry-pi, I set up a buddy of mine with one built on a pi model 1 and a usb hdd he had laying around.
     
    Last edited: Apr 6, 2020