Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity find all scriptable objects of a type

 public static T[] GetAllInstances<T>() where T : ScriptableObject
     {
         string[] guids = AssetDatabase.FindAssets("t:"+ typeof(T).Name);  //FindAssets uses tags check documentation for more info
         T[] a = new T[guids.Length];
         for(int i =0;i<guids.Length;i++)         //probably could get optimized 
         {
             string path = AssetDatabase.GUIDToAssetPath(guids[i]);
             a[i] = AssetDatabase.LoadAssetAtPath<T>(path);
         }
 
         return a;
 
     }
Comment

unity find all scriptable objects of a type

public class CharacterList
    {
        List<Character> characterList = new List<Character>();

        void PopulateList()
        {
            string[] assetNames = AssetDatabase.FindAssets("Your_Filter", new[] { "Assets/YourFolder" });
            characterList.Clear();
            foreach (string SOName in assetNames)
            {
                var SOpath    = AssetDatabase.GUIDToAssetPath(SOName);
                var character = AssetDatabase.LoadAssetAtPath<Character>(SOpath);
                characterList.Add(character);
            }
        }
    }
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to round to nearest number in array c# 
Csharp :: c# generic enum value to int 
Csharp :: asp.net c# get user email address from AD 
Csharp :: How to install a windows service programmatically in C#? 
Csharp :: toLocalIsoString() vs toIsoString() 
Csharp :: find gameobject by name in root 
Csharp :: unity gui button width 
Csharp :: count number of rows in a table in c# 
Csharp :: unity audiosource play 
Csharp :: length of list c# 
Csharp :: cursor position c# 
Csharp :: lwjgl fullscreen 
Csharp :: c# copy bidimensional array 
Csharp :: boxing and unboxing in c# 
Csharp :: generate random light colors programatically in android 
Csharp :: unity navmeshagent set destination 
Csharp :: oncollisionenter2d 
Csharp :: car controller unity 
Csharp :: how to convert int to string c# 
Csharp :: how to empty an array c# 
Csharp :: c# console.writeline 
Csharp :: c# exception middleware 
Csharp :: How to invoke an AWS Lambda function asynchronously 
Csharp :: c# exit foreach 
Csharp :: Implementing video array in unity 
Csharp :: unity image button 
Csharp :: c sharp xml prettier 
Csharp :: Go Statement in CSharp 
Csharp :: C# HttpUtility not found / missing C# 
Csharp :: core ui switch 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =