- Home /
Get a Sprite from a non instantiated Prefab
I looked around a bit and really couldn't find anything that answers this, but how do i get a sprite from a prefab that is not instatiated to show on a UI Image?
Answer by Arcana96 · Mar 27, 2018 at 02:13 AM
A simple way to load a sprite into your game is to use the Resources.Load() method. Essentially you create a "Resources" folder in the route of your project folder and anything you store within there can be loaded using that method.
An example of the file structure would be:
-Root --Resources ---Sprites ----UiImage.png
to get "UiImage. png" you would do the following :
Image.sprite = Resources.Load(Sprites/UiImage.png);
Hope that helps.
I do have a resources folder, but like, i want to access a sprite within a specific prefab from that folder, and i don't really know how to go about that
You'd have to instantiate the prefab into an object to get grab any component data from it. You should look up scriptable objects they might be what you're looking for.
ok, so, i looked into scriptable objects but i don't know how to apply them in this case, do you have any link to a tutorial of some sort? i'm very new to coding and kind of dumb to understand stuff lmao
Your answer
Follow this Question
Related Questions
Overlapping objects increase drawcalls in 2DToolkit 0 Answers
Get all sprites of the prefab in order and change their sprite 1 Answer
Get the sprite name attached to Source Image of UI Image 3 Answers
Quality of Texture2D.LoadImage() is different from preloaded sprite asset 2 Answers
Loosing sprite association when transferring prefab 1 Answer