Search Unity

How to load assets at runtime from within a UPM package?

Discussion in 'Package Manager' started by oshoham, Sep 8, 2019.

  1. oshoham

    oshoham

    Joined:
    Oct 12, 2017
    Posts:
    2
    Hi, I've been developing a Unity package, and I'm running into an issue with loading assets from my package at runtime. As far as I can tell, Resouces.Load() doesn't work because packages are installed outside of the Assets folder.

    So far, I've come across this documentation on loading package assets via AssetDatabase.LoadAssetAtPath(), which works great in the Editor, but doesn't work in a build, because AssetDatabase is part of UnityEditor. Is there another solution to this problem that will work in the both the Editor and in a build? Or is there some way to get Resources.Load() working with assets located in a package?

    Thanks!
     
  2. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    267
    TextMesh Pro package copied runtime assets into Assets folder...
     
  3. oshoham

    oshoham

    Joined:
    Oct 12, 2017
    Posts:
    2
    If anyone comes across this in the future, turns out I was wrong - you can put a Resources folder in your UPM package and it'll work as expected.