- Home /
How can I load the UISprite builtin resource at runtime?
Hi all,
I've tried to load the resource using Resources.GetBuiltinResource<Sprite>("unity_builtin_extra/UISprite") but it doesn't work.
Has anyone had luck with this?
Thanks,
Answer by NoScopingDude · Jul 05, 2020 at 10:15 AM
Found this post: https://forum.unity.com/threads/accessing-ui-build-in-sprites-in-c.305075/
private const string kStandardSpritePath = "UI/Skin/UISprite.psd";
private const string kBackgroundSpriteResourcePath = "UI/Skin/Background.psd";
private const string kInputFieldBackgroundPath = "UI/Skin/InputFieldBackground.psd";
private const string kKnobPath = "UI/Skin/Knob.psd";
private const string kCheckmarkPath = "UI/Skin/Checkmark.psd";
Then you do (example shows using background sprite):
AssetDatabase.GetBuiltinExtraResource("UI/Skin/Background.psd");
Additionally you might have to change the image type (that is true for background):
Image someImage = ...;
someImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Background.psd");
someImage.type = Image.Type.Sliced;
You can see the type by simply choosing the image in the inspector.
Your answer
Follow this Question
Related Questions
Make images fit in UI 0 Answers
Animation axis of UI element reversed (bug?) 0 Answers
How to change UI image render order dynamically on runtime 1 Answer
Change UI GUI Image Sprite at runtime .. Unity 5 .. js 1 Answer
Weird UI.image with not sprite, chooses random sprite based on position. 2 Answers