- Home /
Basic Question about TextAssets
This is a totally beginner-level type question, but I can't find anything anywhere.
So, I'm trying to figure out how to read the contents of a text file. I've imported the file as a TextAsset into the Assets folder. I see that I could stick it into a Resources folder and load it that way, but everything I'm reading is saying that this is generally not the best way to do things in Unity. The Scripting Reference page on Resources says:
"In Unity you usually don't use path names to access assets, instead you expose a reference to an asset by declaring a member-variable, and then assign it in the inspector. When using this technique Unity can automatically calculate which assets are used when building a player. This radically minimizes the size of your players to the assets that you actually use in the built game. "
Well, that sounds great! One problem though. I have no clue whatsoever how I'm supposed to go about "exposing a reference to an asset by declaring a member-variable, and then assigning it in the inspector." I don't have the slightest idea what that means or how to do that.
Like I said, this is obviously a very basic-level question, and I'm sure it's been asked a million times before and I've just been unable to find a thread on it, or I'm sure there's some page in the Unity documentation that I overlooked that explains it. But, I'm at a loss! So if someone could point me in the direction of where I need to look for this, I'd appreciate it.
public TextAsset myConfigFile;
do this declaration in the class you want to access the file from and then attach the script to an object in scene. Now you can just drag and drop the file to the $$anonymous$$y Config File varialble you see in the editor.
Your answer
Follow this Question
Related Questions
How does a TextAsset work? 1 Answer
Loading TextAsset returns null 1 Answer
How can I get game data from a specified file? 0 Answers
Confused about intermediate string reading. 1 Answer
Finding the height of a text asset. 1 Answer