Search Unity

Sprite won't load

Discussion in '2D' started by Pincalibur, Apr 7, 2015.

  1. Pincalibur

    Pincalibur

    Joined:
    Feb 2, 2015
    Posts:
    2
    Hi there,
    I want to load a Sprite, that I imported to my project, and replace another Sprite in my SpriteRenderer with it.
    So I load my Sprite:
    spriteX = Resources.Load<UnityEngine.Sprite>("Sprites/xmark");

    And I want to place another Sprite with it:
    clickedField.GetComponent <SpriteRenderer>().sprite = spriteX;

    But I'll just get "None" in my SpriteRenderer.
    My file "xmark.png" is in my created folder "Sprites".

    Any clues on what I am doing wrong?
     
  2. Leo-Yaik

    Leo-Yaik

    Unity Technologies

    Joined:
    Aug 13, 2014
    Posts:
    436
    Hi

    The Resources.Load() will first look for assets to load from all folders with the name "Resources" under your project folder.

    In your case, you need to place them under

    Assets
    - Resources
    - Sprite
    - xmark.png
     
    Pincalibur likes this.
  3. Pincalibur

    Pincalibur

    Joined:
    Feb 2, 2015
    Posts:
    2
    Okay I got it now.
    I created a new Folder Resources, put my Sprites Folder into it and thats it.
    Thanks for your help!