Hi All
I have facing a problem while loading images dynamically from a particular folder in unity
Following is a code which I am trying:-
EDIT: Code Modified
using UnityEngine; using System.Collections;
public class GenrateImages : MonoBehaviour { // This is the Path where my images are stored.I am Fetching the images from external folder. // I my project i have stored images in "D:UnityPractiseExamplesDynamicScrollBarAssetsResources". //public string imagePath = @"C:UsersPublicPicturesSample Pictures"; public string imagePath = "D:/UnityPractiseExamples/DynamicScrollBar/Assets/Resources/"; //public string imagePath; Texture2D[] typedTextures; int displayed = 0;
// Use this for initialization
void Start () {
Object[] textures = Resources.LoadAll(imagePath, typeof(Texture2D));
typedTextures = new Texture2D[textures.Length];
for (int i = 0; i < textures.Length; i++){
typedTextures _= (Texture2D)textures*;*_
The thing you have to beware of with Resources.Load is that does not in fact load images, or any other assets, from the original files. It loads them from a single file called resources.assets into which all assets are packed when your project is built. Unity will package all assets located in any folder called “Resources” into this file, but it will not load assets from anywhere else. If you want something to be loadable with Resources.Load, then the asset MUST be stored in a folder called Resources, or a subfolder thereof. See this page for more information:
This behaviour can be a little confusing at first because Resources.Load works with paths and filenames when you load data from it. So at a glance, it seems intuitive to expect it to be able to load resources from any path you give it. But it’s important to remember that the data is not loaded from files, and you do not have to copy the original source files into the folder when you build.
If you find you can’t load any resources, it’s probably because of any of these common mistakes:
The file is not stored in a folder called “Resources” in the editor.
You got the path wrong in the string you pass to Resources.Load. The path is relative to any Resources folder
You added extensions to the filenames you’re trying to load.
You used backslashes in the path. Resources.Load works with forward slashes ONLY.
If you want to load actual files outside Unity’s Resources package system, e.g. because you need to ship extra assets after building the app, then you need to look into AssetBundles, which provide that option.
ok, just to be very clear what you’re trying to do is unusual - Unity expects all the assets used in your game to belong to the Assets folder you already used to know in your Unity projects, and if you want to load a texture dynamically as you wish, better be in a folder named Resources. I attached a demo scene to show you that this way it works painlessly but ,if you terribly need to load a texture outside your game assets, then you have to keep in mind that you can’t use the Resource object to do that but rather use some other technique - if any exists - but there I’m unable to help you.