Search Unity

Feedback best practive modifiying libraries

Discussion in 'Editor & General Support' started by tree_arb, Feb 8, 2023.

  1. tree_arb

    tree_arb

    Joined:
    Dec 30, 2019
    Posts:
    323
    Lets say i have an asset with some private methods for dragging, or whatever.
    Outside of this I want to know when (asset.isDragging)

    I can create that bool or event but either way i am opening and modifying that third party class directly.

    What might be the best way to keep the original asset untouched in this scenario, where there are no events or public api...currently I usually just open and modify the source code
     
  2. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    720
    There's no shame in just reaching in and messing with the library, tbh.

    The alternative is reflection. It lets you access classes, methods, and fields by name at runtime. I don't have any specific resources in mind, but you can have a look at the Microsoft docs for the topic.
     
    tree_arb likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    I like to leverage source control whenever I have to modify a third party library.

    First I would add the entire library source to my project.

    I would make sure (to the extent possible) that it lives entirely in its own folder.

    I would commit it fully unmodified with nothing else in the commit.

    All subsequent updates to it would be committed as pure changes to that folder, no other changes.

    This has served me well: when the library gets updated I can just drop the new one in, commit it, and then hand-revert the changes in that commit that wiped out my changes, capturing those in a second commit.

    This scales to a point but does require meticulous attention to commit purity.
     
    tree_arb likes this.
  4. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    720
    Ah, yes, you should give that some attention -- in the past, I've been surprised when I discovered that my modifications weren't getting source-controlled.

    This is particularly annoying for paid assets that you don't keep in your source tree.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    Yes, you absolutely would need to "unpack and bake" a Package-Mangler-delivered asset, moving it from the package cache over to your Assets/ folder and removing it from your
    manifest.json
    .

    Then just keep a spare copy of the manifest.json file somewhere else in your repo so you can know positively which version you came from.

    Ideally, don't modify third party code, but sometimes you have no better choice.
     
  6. tree_arb

    tree_arb

    Joined:
    Dec 30, 2019
    Posts:
    323
    ah ok i like this.
     
    Kurt-Dekker likes this.