In my Unity project a have several instanced of the class ArmourType (these are assets, scriptable objects). I'm trying to show these in a dropdown list in the inspector, and this works. However, I use
List<ArmourType> armourTypes = Resources.FindObjectsOfTypeAll<ArmourType>();
to find all these instances. This only finds the objects that are loaded into memory, so occasionally it only finds some of the required assets. This is documented, so isn't a bug, but very annoying at times.
So my question is, is there a different way of getting all these assets that does return those that aren't loaded into memory? Or perhaps is there a way to make Unity load the assets when they are looked for?
Note: I'm using Unity5 and c#.
Editor versions 2019.4 and below: Open the Unity Editor and launch an existing project (or create a new one). Click Window > Asset Store. Log into your Unity account to access the Asset Store, if prompted. Find the asset you want to download by using the search bar inside the Asset Store window at the top of the page.
The Resources class allows you to find and access Objects including assets. In the editor, Resources. FindObjectsOfTypeAll can be used to locate assets and Scene objects. All assets that are in a folder named "Resources" anywhere in the Assets folder can be accessed via the Resources.
Use the Asset Search Provider to search all Assets in the current Project. You can search using keywords or GUIDs (Instance IDs). You can also search the Asset Database or the file system from the Quick Search window. Default action: Open the Asset, either in Unity or in an external editor.
Is this what you are looking for?
string[] guids = AssetDatabase.FindAssets ("t:ArmourType", null);
foreach (string guid in guids) {
Debug.Log (AssetDatabase.GUIDToAssetPath(guid));
}
http://docs.unity3d.com/ScriptReference/AssetDatabase.FindAssets.html
AssetDatabase is an Editor script. If you want to do a similar thing in-game place the relevant scripts in a Resources folder (this ensures they will be included in the build even if not linked in the scene) and use:
Resources.LoadAll<ArmourType>("");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With