Search Unity

Possible to Resources.Load Assets From Package?

Discussion in 'Package Manager' started by MegamaDev, Oct 26, 2019.

  1. MegamaDev

    MegamaDev

    Joined:
    Jul 17, 2017
    Posts:
    77
    I have a Screen Transitions package which I use to create fades, wipes, iris-outs, etc. across multiple projects. At the moment, all of these effects are based on regular mesh rendering, and they all use a single material and a single shader; I figured I could save some time by putting material and shader in the package alongside the code.

    The material, which has the shader assigned to it in usual material fashion, is in a Resources folder at the root of the package. Nonetheless, when I attempt to
    Resources.Load<Material>("Transition")
    , I end up with the default , which makes the screen transitions very ineffectual indeed. I've also tried loading from
    "Resources/Transition"
    and from
    "Packages/com.clouds.screentransitions/Resources/Transition"
    , but in both cases I get nothing.

    Am I wasting my time here? Should I just bite the bullet and make a local copy of the material for each project I do? Or is there actually a way to
    Resources.Load(...)
    assets from inside a package?
     
    Last edited: Oct 26, 2019
  2. okcompute_unity

    okcompute_unity

    Unity Technologies

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

    If you are using Unity 2018.3 or higher, may I suggest using the new Addessables package to add assets from a package? This will be more efficient and it is also the recommended way to add assets from a package into a player. See the package documentation for more details.

    Regards,

    Pascal
     
  3. MegamaDev

    MegamaDev

    Joined:
    Jul 17, 2017
    Posts:
    77
    Huh. You know, I hadn't thought of that.

    At the time of my initial writing, I thought Addressables were for Asset Bundles only, but I have since experimented with them a bit (unrelated to this) and discovered that they're not just for Asset Bundles.

    Thanks for pointing this approach out!