Search Unity

Editing and tracking changes to package files

Discussion in 'Package Manager' started by nickfourtimes, Mar 19, 2019.

  1. nickfourtimes

    nickfourtimes

    Joined:
    Oct 13, 2010
    Posts:
    219
    This may have been asked already, and/or this may run counter to what the PM provides; and in my case, it's very specific to TextMesh Pro.

    I'm hoping to add custom rich text tags to TMP. As outlined in this post, that can be done by editing the following file:
    TextMesh Pro/Scripts/Runtime/TMP_Text.cs

    Previously, if I obtained TMP from the Asset Store, it would become part of my project and could be committed via e.g., git. I could change the file myself, commit it, and then restore my change if some future version of TMP overwrote it.

    Now, however, the required file is in the packages folder, outside of my project folder (by design). The file is also marked as read-only (which I can get around). Most importantly to me though, is that any future updates to the package will silently and irretrievably overwrite any changes I've added to TMP.

    Again I realise that a lot of this stuff is probably by design, but is there a workaround/best practice for making edits to official Unity packages?
     
    Last edited: Mar 20, 2019
  2. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    318
    Here's a modular approach that I'm using at work. You can make your own local package called com.you.textmeshpro.extensions with its own assembly definition file and namespace and make that package have a dependency on TMP. It could be written to extend/inherit from the APIs provided in the original Unity package. Then you can simply use the types you define there to do whatever you wanted to do.

    With this set up, you don't have to care what new version of TMP is released (unless there's some significant API changes) since you're just managing your own versioning for JUST the code that you wrote.

    Though this all depends on the exact nature of what custom edits you're doing. Works much better for additions than it does for direct changes.
     
  3. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    you can embed the package and track it with git.
    now it's a manual process:
    - copy the package from
    Library/PackageCache
    to
    Packages
    via explorer/finder
    - strip the version tag (
    [USER=473422]@...[/USER]
    ) from the name, leaving only e.g.
    com.unity.textmeshpro

    - unmark the readonly status
    - return to unity
    - now the package is editable and gittable. track your modifications

    to update, delete the folder, repeat the process and reapply the diff(s)
     
    booferei, Clonkex, skullthug and 4 others like this.
  4. nickfourtimes

    nickfourtimes

    Joined:
    Oct 13, 2010
    Posts:
    219
    Hm. I suppose these are a bit similar, just making a copy of the package in my local (tracked) project folder. The change I'm hoping to make is a bit fundamental though (I think), rather than a small extension, so I'd probably go with the second option here.

    However, I don't have a folder called Library/PackageCache in my project folder (though there are a few other *Cache folders, it seems). I suppose I can just right-click on the package in the Project view, in Project -> Packages -> TextMesh Pro and choose "Show in Explorer," which brings me to the folder on disk. I can copy that over to my project directory, and "Remove" TMP from my list of packages in the package manager.

    I guess the only issue with that is now having to manually check whether TMP's been updated, and proceeding with the manual update as outlined above. Not ideal, but I guess that's the only option for now.
     
  5. projectorgames_unity

    projectorgames_unity

    Joined:
    Oct 15, 2018
    Posts:
    107
    Bit confused why you think this would work; now I just get plenty of messages like.

    Assembly with name 'Unity.RenderPipeline.Universal.ShaderLibrary' already exists (Assets/Packages/com.unity.render-pipelines.universal/ShaderLibrary/Unity.RenderPipelines.Universal.ShaderLibrary.asmdef)


    I'm unable to find any solution to this rather stupid issue.
     
  6. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    Did you just try it? That reply is almost two years old and a lot has changed in that time. I'll ask the team to take a look at this thread and see if there is anything they can advise.
     
  7. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    556
    I think the problem is that you copied the package to
    Assets/Packages/com.unity.render-pipelines.universal
    , under Assets, when in fact it should be directly outside of it, under
    Packages/com.unity.render-pipelines.universal
    (that is, in the Packages directory located at the root of your project directory).

    For more information, please see Embedded dependencies in the Unity Manual.
     
  8. projectorgames_unity

    projectorgames_unity

    Joined:
    Oct 15, 2018
    Posts:
    107
    If you overwrite a file in the Packages folder, overwriting the defaults, Unity simply reverts it each time you launch the editor. I found dozens of threads with this issue, but no solution (barring re-copying the file in a script each time you alter anything)

    The suggestion in this thread was to make a second copy, not overwriting it, so of course you'll get 'this already exists'

    Quite frankly I'm unsure of the point in supplying us with the source code for things like URP if it's not trivial to update it locally.
     
  9. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    556
    Unity reverts package files it manages automatically under
    <project>/Library/PackageCache
    , not those you manage yourself under
    <project>/Packages
    .

    Note that to customize a package, you must copy the whole package, not just a single file, and it must not be located under
    <project>/Assets
    , because the Package Manager doesn't look at the
    Assets
    folder at all, so it will not detect any package there. An embedded package must be under
    <project>/Packages
    , where the Package Manager will detect it, and use it instead of retrieving a copy into the
    <project>/Library/PackageCache
    folder.

    I understand it may be confusing to see all these potential package locations. Simply put,
    <project>/Library/PackageCache
    is a location where the Package Manager stores packages it retrieved externally (from a registry, a Git repository, a .tgz file...) while
    <project>/Packages
    is a location for package customization and user packages. That is, embedding a package into the project by copying to that location is one way to customize packages.

    To make it clear: Unity should not revert any file under
    <project>/Packages
    . If it does, it's likely a bug, and we would really appreciate if you could report it using the Help > Report a Bug menu so we get a copy of useful files like the Editor.log that we can use to investigate.
     
    Last edited: Jan 19, 2021
  10. projectorgames_unity

    projectorgames_unity

    Joined:
    Oct 15, 2018
    Posts:
    107
    I'll check that - wish I'd found this information somewhere else on the internet!
     
  11. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    556
    This information is available in the Unity Manual. There are also many posts on this forum that discuss embedding packages.

    But that said, I agree that the Manual could have been clearer about embedded packages being useful to customize existing packages, nor does it provide the steps to manually do it (it does mention you can use the scripting API
    Client.Embed
    but this may not be as straightforward). Currently, it may easily be interpreted to imply that embedded packages can only be your own custom packages. We will look into improving this.
     
    EthanFischer likes this.