- Home /
Using pre existing assets on runtime
I am trying to load Pre-Existing assets on runtime in a script.
Example: I have a custom font I want to use in a Text Mesh. It is already loaded in the editor, I can apply it a Text Mesh with the editor. However when I want to use it on runtime I can not figure out a way to use it.
How do you use a pre existing asset on runtime?
Unity's built players don't ship with the editor code, which includes most of the utilities for importing assets. There are a few asset types you can still import (textures and some audio, mostly).
A font? You can certainly import a font in the editor, but doing so in a built player is going to require a plugin. You may be able to find one, or you might need to build it yourself.
I'm reluctant to let this through the mod queue, because it's a frequently asked question. If you can't find help, here, you might look for one of those plugins, or you might try the forums.
Answer by gcoope · Jul 25, 2014 at 01:50 PM
You can create a folder on the root of your project named "Resources". Unity will treat this Resources folder differently, in that you can load from it at runtime.
You can load from it using the following format:
GameObject enemy = Resources.Load("enemyPrefab");
Or in your example:
Font myFont = Resources.Load("myFontName");
Source: http://docs.unity3d.com/ScriptReference/Resources.Load.html
Thanks, I believe you would have to cast to type Font
for your second example though, so Font myFont = (Font) Resources.Load("font");
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
A node in a childnode? 1 Answer
new Line in a CustomPropertyDrawer 1 Answer
Simple Timer 2 Answers
Build DLL using Visual Scripting Tool? 0 Answers