Search Unity

(How) can you apply patches to packaged assets?

Discussion in 'Package Manager' started by TwiiK, May 16, 2018.

  1. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    I find that very often there's a need to change something locally while you're waiting for a fix to be commited or sometimes you just outright disagree with something and want it changed permanently on your end, and in those cases it's necessary to be able to apply patches to the packaged assets.

    An example here is the post processing stack which has an artifact with the bloom which makes it unusable for me. This pull request fixes it https://github.com/Unity-Technologies/PostProcessing/pull/564, but there's no saying when or if that pull request will ever be pulled into the master branch. So at the moment that means I can't use the packaged post processing asset and instead have to add it to my project manually so that I can apply those changes to it.
     
  2. erick_unity

    erick_unity

    Unity Technologies

    Joined:
    Jan 4, 2017
    Posts:
    41
    Hi Twiik, just to clarify, are you asking for a mechanism to get your proposed changes accepted in github and thereafter an official version of the patched package, or do you want a way to embed a package with modifications into your project without having to pollute your "assets" directory?
     
  3. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    At work we use Composer as a package manger for PHP which works in much the same way as the Unity package manager as far as I can tell, but often there's either something we need to fix locally while we're waiting for a fix to happen to the official packaged asset (which we don't control the timeline for) or we just want to alter how the packaged asset behaves in some projects. So we tweak the code of the packaged asset, but if we just left it like that it would be overwritten the next time the asset was updated so we create a git patch from the code changes which the package manager automatically applies every time it builds the project. It does this through a syntax like this in the json-file:

    Code (JavaScript):
    1. "patches": {
    2.   "official/core": {
    3.     "Description of what the patch does": "https://url-to-patch-on-github.com/e945c6f0e5695f8.patch"
    4.   },
    5.   "custom/something": {
    6.     Description of what the patch does": "file://local-url-to-patch/264051627.patch"
    7.   }
    8. }
    Here you have the package provider and the package to patch, a description of the patch and where to find the patch.

    But I just realized I don't know where the Unity package manager stores the packaged assets that I'm using in my project. I assumed they were in the "Packages" directory, but it only contains the manifest.json file. If we're not able to easily alter the code of a packaged asset used in our projects I feel like that's a bit of a wasted opportunity. Because so much of Unity is closed off from us being able to easily tweak the parts that are not could be one of the goals with the package manager in my opinion.

    I found this guide yesterday (https://gist.github.com/LotteMakesStuff/6e02e0ea303030517a071a1c81eb016e) which tells me I could for example download the post processing stack from github, patch in the changes I want, and use my custom version of the post processing stack as a custom packaged asset in my projects, but if I wanted separate changes for each project I wouldn't have an easy way of achieving that. And all of this is of course a cumbersome workaround for something that could work a lot easier if support was built-in.

    I love the idea of the package manager, but something like this is essential for me to be able to use it. So far I've used Anima2D, TextMeshPro and the Post Processing stack V2 before the package manager arrived and I've felt a need to make changes to all of them to be able to use them in my projects. And something like the pull request I linked above is a prime example of why, but like I said sometimes the changes I want are changes that are never going to be added into an official release so it's not just about saving time while waiting either, it's about the practicality of being able to use the same asset in all our projects, but with the flexibility to easily tweak them to our liking.
     
    BaalEvan likes this.
  4. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    The packages live in a central cache on your computer. You can find the locations in this post: #7

    If you want a per-specific-project local copy you should be able to copy the required folders from the cache to the Packages folder within the root of your project folder. When I have talked about this in the past, people from Unity have said that they refer to this as embedding a package, and official support for this is planned but not officially supported yet. It has always worked for me when I tried, but I've only tried with a few packages so far (render pipeline stuff mostly). Also note that Unity 2018.2 allows contents in Packages to be seen in the editor asset browser. To be honest you could probably also just copy some of the packages directly into folders within your assets folder and it would probably work too (eg when I use a github version of a scriptable render pipeline, I stick it in subfolder in Assets and it works).

    A few other posts where I went into more detail about this and other somewhat related matters, in response to slightly different requests to yours, and a few misconceptions about compiled dll versions:

    https://forum.unity.com/threads/how-to-move-packages-to-an-offline-installation.529318/#post-3480591

    https://forum.unity.com/threads/dep...ages-instead-of-dll-form.528832/#post-3477838
     
  5. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    755
    It's very common with third party assets to have to make some kind of code change, either to add in a feature yourself, or a fix while waiting on an update to include that fix. I hope there will be a way to handle this nicely in the Package Manager while still maintaining the ability to update without losing your changes.