Search Unity

Trying to create manual Embed tool

Discussion in 'Package Manager' started by amarcolina_oculus, Aug 20, 2019.

  1. amarcolina_oculus

    amarcolina_oculus

    Joined:
    Apr 16, 2019
    Posts:
    7
    Unity 2019.2 added the very useful Client.Embed method. Unfortunately I am working with some people who are still stuck on earlier versions of Unity, but still want to use the embed functionality. I figured it would be easy enough to write a fallback, but I am running into some very strange behavior that I would like some clarity on.

    There seems to be some sort of mechanism in place to make packages appear to the filesystem as though they are in the Packages folder, even though they are located inside of Library/PackageCache.

    If I log the results of
    Directory.GetDirectories("<pathtoproject>/Packages")

    I see nothing. But if I do
    Directory.GetFiles("<pathtoproject>/Packages/packagename")

    I see all of the files that are located in the package, but furthermore, all of the full paths to those files show they are indeed located at
    <pathtoproject>/Library/PackageCache/packagename/

    instead!

    I am unfamiliar with whatever mechanism is in place that can cause this to happen, but the reason I ran into it is because I am simply trying to move the package contents from the PackageCache folder into the Packages folder, but due to this strange mechanism, the operation fails because it considers it already at the destination location! Is there any way I can get around this behavior, and create an Embed fallback that can function in the same or similar way?
     
  2. okcompute_unity

    okcompute_unity

    Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    756
    Hi @amarcolina_oculus ,

    The Package Manager uses a virtual file system to hook up package folder in Unity. They can be anywhere in your system (in the past, we used to link directly to the path in the global cache but some features required to make a copy in the project cache). The registration is done per package in the VFS. The
    /Packages
    path is not registered. It physically exists and this is where embedded packages lie. If you use the full absolute path instead, I believe you should be able to copy folders from the cache to
    /Packages
    .

    Let me know if it works.

    Regards,

    Pascal[/icode]
     
  3. amarcolina_oculus

    amarcolina_oculus

    Joined:
    Apr 16, 2019
    Posts:
    7
    Hmm, I was using full absolute paths from the start, and wasn't having any luck. I found a workaround where I first copy the package to a temporary directory, then uninstall the package via the Client interface, and then finally re-install the package by copying it to the Packages directory. This seems to get around the issue because the package has already been uninstalled by the time I copy to the Packages directory.

    Thanks for your help!
     
  4. amarcolina_oculus

    amarcolina_oculus

    Joined:
    Apr 16, 2019
    Posts:
    7
    Ahh, I spoke too soon, and am now running into another issue. So for the virtual file system, one of the problems might be that the csharp code I am running that tries to move the directory is running from inside of Unity. Might there be a way to get around this virtual file system by creating a new AppDomain, or something along those lines?
     
  5. okcompute_unity

    okcompute_unity

    Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    756
    You could launch a shell command using the
    Process
    class?
     
    amarcolina_oculus likes this.
  6. amarcolina_oculus

    amarcolina_oculus

    Joined:
    Apr 16, 2019
    Posts:
    7
    That seems to do the trick, thanks for the help!
     
    okcompute_unity likes this.