1

loading an object in Unity would be

Resources.Load("myObject") as GameObject;

Yes you can use the inspector but I want to load it from the Resources folder.

My first question:

What if you have some subfolders in your Resources folder? For example GameObjects, Sounds, Models.

You would have to add a path to the current directory. This was removed

https://docs.unity3d.com/ScriptReference/Resources.LoadAssetAtPath.html

So the code would be something like this

(Resources + "thePath").Load("myObject") as GameObject;

My second question:

Would there be any problems putting the whole project into the resources folder? The path variable would contain more content but would you come up with troubles? Because everything relies to the Resources folder then.

Question3r
  • 2,166
  • 19
  • 100
  • 200

1 Answers1

1

Regarding your first question Resource.LoadAssetAtPath has been deprecated and removed but as noted in the documentation you can use AssetDatabase.LoadAssetAtPath instead: https://docs.unity3d.com/ScriptReference/AssetDatabase.LoadAssetAtPath.html

So to load a resource using the path your can do:

Texture2D t = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/Textures/texture.jpg", typeof(Texture2D));

Regarding your second question, I don't see any reliability problem in using the resources folder to store any asset you want to reference using Resources.Load.

Isma
  • 14,604
  • 5
  • 37
  • 51
  • This is wrong. This answer will only work in the Editor. OP cannot build project with this. I think I should mention this before new users start getting affected by it. – Programmer Dec 17 '17 at 15:26