Is it possible to access or load an Asset at runtime?

I’ve got a basic state machine for a text adventure and I’m trying to figure out how I can jump to any state from within the game script.

Something like this where I can get the state and then work with it.

State jumpToState = Resources.Load("11") as State;
textComponent.text = state.GetStateStory();

I’ve got a state named “11” in my Assets folder and it’s of type ScriptableObject.

It has to be in a folder called Resources (obviously also under Assets somehwere) and then the above should work.

However, please use this format of the line 2 above:

State jumpToState = Resources.Load<State>( "11");

because it will guard against Unity asset ordering inconsistencies that might trip you up, i.e, if you have a texture or material in that same directory called 11.png or 11.mat, the way it was originally written may return the wrong object.

1 Like

That worked. Thanks!

1 Like

BTW, hearing of you making a text adventure in Unity3D here in 2019 really made me smile. I grew up with all the Infocom early stuff, so I just wanna say, “Cool!”

In other news, you oughta post a link here on the forums (there’s a show-off group separate from this group) when you get your first playable going!