Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Load sprite from asset (from asset store) at runtime

Discussion in 'General Graphics' started by SimRuJ, Oct 11, 2018 at 5:16 PM.

  1. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    80
    I "bought" a free asset with icons (it includes the ".png" files) in the asset store and want to change the sprite of a button from one of the icons to another when I click on the button.

    I know that you can load a ".png" file from the "Assets/Resources" folder like this:

    myButton.GetComponent<Image>().sprite = Resources.Load<Sprite>("PathToFile");


    Is it possible to load the icons from the asset's folder that was created when I downloaded it (the path's something like "Assets/IconAsset/128x/icon1.png") at runtime or do I have to copy the files I want to "Assets/Resources" and rename them?

    What I'm looking for is doing the same thing selecting the source image in the Inspector does, except with code.