ScriptableList<T> Class
Definition
Section titled “Definition”A UnityEngine.ScriptableObject that holds a List<T>.
public abstract class ScriptableList<T> : ScriptableList, INotifyPropertyChanging, INotifyPropertyChanged, IStackTraceProvider, ICanBeReadOnly, INotifyCollectionChanged, IList<T>, ICollection<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable, INotifyScriptableCollectionChanged<T>Type Parameters
Section titled “Type Parameters”T
The type of elements in the list.
Inheritance object → UnityEngine.Object → UnityEngine.ScriptableObject → RuntimeScriptableObject → ScriptableList
Implements INotifyPropertyChanging, INotifyPropertyChanged, IStackTraceProvider, ICanBeReadOnly, INotifyCollectionChanged, IList<T>, ICollection<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable, INotifyScriptableCollectionChanged<T>
Properties
Section titled “Properties”Capacity
Section titled “Capacity”Gets the total number of elements the internal data structure can hold without resizing.
public override sealed int Capacity { get; set; }Gets the number of elements contained in the ScriptableList<T>.
public override sealed int Count { get; protected set; }this[int]
Section titled “this[int]”Gets or sets the element at the specified index.
public T this[int index] { get; set; }IsReadOnly
Section titled “IsReadOnly”If read only, the ScriptableList<T> cannot be changed at runtime and won’t be cleared on start.
public override bool IsReadOnly { get; set; }SetEqualityCheck
Section titled “SetEqualityCheck”If true, an equality check will be run before setting an item through the indexer to make sure the new object is not the same as the old one.
public override bool SetEqualityCheck { get; set; }ClearOnStart
Section titled “ClearOnStart”If true, the ScriptableList<T> will be cleared on play mode start/game boot.
public override bool ClearOnStart { get; set; }Methods
Section titled “Methods”Add(T)
Section titled “Add(T)”Adds an item to the end of the ScriptableList<T>.
public void Add(T item)Parameters
Section titled “Parameters”item T
The object to be added to the end of the null for reference types.
Exceptions
Section titled “Exceptions”ReadOnlyException
If the object is read-only and the application is playing.
AddRange(IEnumerable)
Section titled “AddRange(IEnumerable)”Adds the elements of the specified collection to the end of the ScriptableList<T>.
public void AddRange(IEnumerable<T> collection)Parameters
Section titled “Parameters”collection IEnumerable<T>
The collection whose elements should be added to the end of the
null, but it can contain elements that are
null, if type T is a reference type.
Exceptions
Section titled “Exceptions”ArgumentNullException
collection is null.
ReadOnlyException
If the object is read-only and the application is playing.
BinarySearch(T, IComparer?)
Section titled “BinarySearch(T, IComparer?)”Searches the entire sorted ScriptableList<T> for an element using the default comparer and returns the zero-based index of the element.
public int BinarySearch(T item, IComparer<T>? comparer = null)Parameters
Section titled “Parameters”item T
The object to locate. The value can be null for reference types.
comparer IComparer<T>
The null to use the default
comparer
Returns
Section titled “Returns”int
The zero-based index of item in the sorted ScriptableList<T>, if item is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than item or, if there is no larger element, the bitwise complement of Count.
Exceptions
Section titled “Exceptions”InvalidOperationException
comparer is null, and the default comparer cannot find an implementation of the IComparer<T> generic interface or the IComparable interface for type T.
BinarySearch(int, int, T, IComparer?)
Section titled “BinarySearch(int, int, T, IComparer?)”Searches a range of elements in the sorted ScriptableList<T> for an element using the specified comparer and returns the zero-based index of the element.
public int BinarySearch(int index, int count, T item, IComparer<T>? comparer = null)Parameters
Section titled “Parameters”index int
The zero-based starting index of the range to search.
count int
The length of the range to search.
item T
The object to locate. The value can be null for reference types.
comparer IComparer<T>
The null to use
the default comparer
Returns
Section titled “Returns”int
The zero-based index of item in the sorted ScriptableList<T>, if item is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than item or, if there is no larger element, the bitwise complement of index plus count.
Exceptions
Section titled “Exceptions”ArgumentOutOfRangeException
index is less than 0. -or- count is less than 0.
ArgumentException
index and count do not denote a valid range in the ScriptableList<T>.
InvalidOperationException
comparer is null, and the default comparer cannot find an implementation of the IComparer<T> generic interface or the IComparable interface for type T.
Clear()
Section titled “Clear()”Removes all elements from the ScriptableList<T>.
public override sealed void Clear()Exceptions
Section titled “Exceptions”ReadOnlyException
If the object is read-only and the application is playing.
Contains(T)
Section titled “Contains(T)”Determines whether an element is in the ScriptableList<T>.
public bool Contains(T item)Parameters
Section titled “Parameters”item T
The object to locate in the null for
reference types.
Returns
Section titled “Returns”bool
true if item is found in the ScriptableList<T>; otherwise, false.
ConvertAll(Converter<T, TOutput>)
Section titled “ConvertAll(Converter<T, TOutput>)”Converts the elements in the current ScriptableList<T> to another type, and returns a list containing the converted elements.
public List<TOutput> ConvertAll<TOutput>(Converter<T, TOutput> converter)Parameters
Section titled “Parameters”converter Converter<T, TOutput>
A
Returns
Section titled “Returns”List<TOutput>
A List<T> of the target type containing the converted elements from the current ScriptableList<T>.
Exceptions
Section titled “Exceptions”ArgumentNullException
converter is null.
ConvertAll(ICollection, Converter<T, TOutput>)
Section titled “ConvertAll(ICollection, Converter<T, TOutput>)”Converts the elements in the current list to another type, and copies the converted elements to the specified list.
public void ConvertAll<TOutput>(ICollection<TOutput> destinationList, Converter<T, TOutput> converter)Parameters
Section titled “Parameters”destinationList ICollection<TOutput>
The destination list where the converted items will be copied to.
converter Converter<T, TOutput>
A
Exceptions
Section titled “Exceptions”ArgumentNullException
converter is null.
ReadOnlyException
destinationList is marked as read-only.
CopyTo(T[])
Section titled “CopyTo(T[])”Copies the entire ScriptableList<T> to a compatible one-dimensional array, starting at the beginning of the target array.
public void CopyTo(T[] array)Parameters
Section titled “Parameters”array T[]
The one-dimensional array that is the destination of the elements copied from
Exceptions
Section titled “Exceptions”ArgumentNullException
array is null.
ArgumentException
The number of elements in the source ScriptableList<T> is greater than the number of elements that the destination array can contain.
CopyTo(T[], int)
Section titled “CopyTo(T[], int)”Copies the entire list to a compatible one-dimensional array, starting at the specified index of the target array.
public void CopyTo(T[] array, int arrayIndex)Parameters
Section titled “Parameters”array T[]
The array destination.
arrayIndex int
The index in the destination array where the copying begins.
EnsureCapacity(int)
Section titled “EnsureCapacity(int)”Ensures that the list has at least the specified capacity.
public override sealed void EnsureCapacity(int capacity)Parameters
Section titled “Parameters”capacity int
The minimum capacity to ensure.
Exists(Predicate)
Section titled “Exists(Predicate)”Determines whether the ScriptableList<T> contains elements that match the conditions defined by the specified predicate.
public bool Exists(Predicate<T> match)Parameters
Section titled “Parameters”match Predicate<T>
The
Returns
Section titled “Returns”bool
true if the ScriptableList<T> contains one or more elements that match the conditions defined by the specified predicate; otherwise, false.
Exceptions
Section titled “Exceptions”ArgumentNullException
match is null.
Find(Predicate)
Section titled “Find(Predicate)”Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire ScriptableList<T>.
public T? Find(Predicate<T> match)Parameters
Section titled “Parameters”match Predicate<T>
The
Returns
Section titled “Returns”T
The first element that matches the conditions defined by the specified predicate, if found; otherwise, the default value for type T.
Exceptions
Section titled “Exceptions”ArgumentNullException
match is null.
FindAll(Predicate)
Section titled “FindAll(Predicate)”Retrieves all the elements that match the conditions defined by the specified predicate.
public List<T> FindAll(Predicate<T> match)Parameters
Section titled “Parameters”match Predicate<T>
The
Returns
Section titled “Returns”List<T>
A List<T> containing all the elements that match the conditions defined by the specified predicate, if found; otherwise, an empty List<T>
Exceptions
Section titled “Exceptions”ArgumentNullException
match is null.
FindAll(IList, Predicate)
Section titled “FindAll(IList, Predicate)”Retrieves all the elements that match the conditions defined by the specified predicate and copies them to the specified list.
public void FindAll(IList<T> destinationList, Predicate<T> match)Parameters
Section titled “Parameters”destinationList IList<T>
The list where the found elements will be copied to.
match Predicate<T>
The
Exceptions
Section titled “Exceptions”ArgumentNullException
match is null.
ArgumentException
destinationList is marked as read-only.
FindIndex(Predicate)
Section titled “FindIndex(Predicate)”Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the entire list.
public int FindIndex(Predicate<T> match)Parameters
Section titled “Parameters”match Predicate<T>
The
Returns
Section titled “Returns”int
The zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, -1.
Exceptions
Section titled “Exceptions”ArgumentNullException
match is null.
FindIndex(int, Predicate)
Section titled “FindIndex(int, Predicate)”Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the list that extends from the specified index to the last element.
public int FindIndex(int startIndex, Predicate<T> match)Parameters
Section titled “Parameters”startIndex int
The zero-based starting index of the search.
match Predicate<T>
The
Returns
Section titled “Returns”int
The zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, -1.
Exceptions
Section titled “Exceptions”ArgumentNullException
match is null.
ArgumentOutOfRangeException
startIndex is outside the range of valid indexes for the list.
FindIndex(int, int, Predicate)
Section titled “FindIndex(int, int, Predicate)”Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the list that starts at the specified index and contains the specified number of elements.
public int FindIndex(int startIndex, int count, Predicate<T> match)Parameters
Section titled “Parameters”startIndex int
The zero-based starting index of the search.
count int
The number of elements in the section to search.
match Predicate<T>
The
Returns
Section titled “Returns”int
The zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, -1.
Exceptions
Section titled “Exceptions”ArgumentNullException
match is null.
ArgumentOutOfRangeException
startIndex is outside the range of valid indexes for the list. Or count is less than 0. Or startIndex and count do not specify a valid section in the list.
FindLast(Predicate)
Section titled “FindLast(Predicate)”Searches for an element that matches the conditions defined by the specified predicate, and returns the last occurrence within the entire list.
public T? FindLast(Predicate<T> match)Parameters
Section titled “Parameters”match Predicate<T>
The
Returns
Section titled “Returns”T
The last element that matches the conditions defined by the specified predicate, if found; otherwise, the default value for type T.
Exceptions
Section titled “Exceptions”ArgumentNullException
match is null.
FindLastIndex(Predicate)
Section titled “FindLastIndex(Predicate)”Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the entire list.
public int FindLastIndex(Predicate<T> match)Parameters
Section titled “Parameters”match Predicate<T>
The
Returns
Section titled “Returns”int
The zero-based index of the last occurrence of an element that matches the conditions defined by match, if found; otherwise, -1.
Exceptions
Section titled “Exceptions”ArgumentNullException
match is null.
FindLastIndex(int, Predicate)
Section titled “FindLastIndex(int, Predicate)”Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the range of elements in the list that extends from the first element to the specified index.
public int FindLastIndex(int startIndex, Predicate<T> match)Parameters
Section titled “Parameters”startIndex int
The zero-based starting index of the backward search.
match Predicate<T>
The
Returns
Section titled “Returns”int
The zero-based index of the last occurrence of an element that matches the conditions defined by match, if found; otherwise, -1.
Exceptions
Section titled “Exceptions”ArgumentNullException
match is null.
ArgumentOutOfRangeException
startIndex is outside the range of valid indexes for the list.
FindLastIndex(int, int, Predicate)
Section titled “FindLastIndex(int, int, Predicate)”Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the range of elements in the list that contains the specified number of elements and ends at the specified index.
public int FindLastIndex(int startIndex, int count, Predicate<T> match)Parameters
Section titled “Parameters”startIndex int
The zero-based starting index of the backward search.
count int
The number of elements in the section to search.
match Predicate<T>
The
Returns
Section titled “Returns”int
The zero-based index of the last occurrence of an element that matches the conditions defined by match, if found; otherwise, -1.
Exceptions
Section titled “Exceptions”ArgumentNullException
match is null.
ArgumentOutOfRangeException
startIndex is outside the range of valid indexes for the list. Or count is less than 0. Or startIndex and count do not specify a valid section in the list.
ForEach(Action)
Section titled “ForEach(Action)”Performs the specified action on each element of the list.
public void ForEach(Action<T> action)Parameters
Section titled “Parameters”action Action<T>
The
Exceptions
Section titled “Exceptions”ArgumentNullException
action is null.
InvalidOperationException
An element in the collection has been modified.
GetEnumerator()
Section titled “GetEnumerator()”Returns an enumerator that iterates through the list.
public List<T>.Enumerator GetEnumerator()Returns
Section titled “Returns”List<T>.Enumerator
A List<T>.Enumerator for the list.
GetRange(int, int)
Section titled “GetRange(int, int)”Creates a shallow copy of a range of elements in the source list.
public List<T> GetRange(int index, int count)Parameters
Section titled “Parameters”index int
The zero-based list index at which the range starts.
count int
The number of elements in the range.
Returns
Section titled “Returns”List<T>
A shallow copy of a range of elements in the source list.
Exceptions
Section titled “Exceptions”ArgumentOutOfRangeException
index is less than 0. Or count is less than 0.
ArgumentException
index and count do not denote a valid range of elements in the list.
GetRange(int, int, IList)
Section titled “GetRange(int, int, IList)”Copies a range of elements from the source list to the specified destination list.
public void GetRange(int index, int count, IList<T> destinationList)Parameters
Section titled “Parameters”index int
The zero-based list index at which the range starts.
count int
The number of elements in the range.
destinationList IList<T>
The list where the copied elements will be stored.
Exceptions
Section titled “Exceptions”ArgumentNullException
destinationList is null.
ArgumentOutOfRangeException
index is less than 0. Or count is less than 0.
ArgumentException
index and count do not denote a valid range of elements in the list.
ArgumentException
destinationList is marked as read-only.
IndexOf(T)
Section titled “IndexOf(T)”Searches for the specified object and returns the zero-based index of the first occurrence within the entire list. Returns -1 if the item is not found.
public int IndexOf(T item)Parameters
Section titled “Parameters”item T
The object to locate in the list.
Returns
Section titled “Returns”int
The zero-based index of the first occurrence of item within the entire list, if found; otherwise, -1.
IndexOf(T, int)
Section titled “IndexOf(T, int)”Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the list that extends from the specified index to the last element.
public int IndexOf(T item, int index)Parameters
Section titled “Parameters”item T
The object to locate in the list.
index int
The zero-based starting index of the search. 0 (zero) is valid in an empty list.
Returns
Section titled “Returns”int
The zero-based index of the first occurrence of item within the range of elements in the list that extends from index to the last element, if found; otherwise, -1.
Exceptions
Section titled “Exceptions”ArgumentOutOfRangeException
index is outside the range of valid indexes for the list.
IndexOf(T, int, int)
Section titled “IndexOf(T, int, int)”Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the list that starts at the specified index and contains the specified number of elements.
public int IndexOf(T item, int index, int count)Parameters
Section titled “Parameters”item T
The object to locate in the list.
index int
The zero-based starting index of the search. 0 (zero) is valid in an empty list.
count int
The number of elements in the section to search.
Returns
Section titled “Returns”int
The zero-based index of the first occurrence of item within the range of elements in the list that extends from index to the last element, if found; otherwise, -1.
Exceptions
Section titled “Exceptions”ArgumentOutOfRangeException
index is outside the range of valid indexes for the list. Or count is less than 0. Or index and count do not specify a valid section in the list.
Insert(int, T)
Section titled “Insert(int, T)”Inserts an element into the list at the specified index.
public void Insert(int index, T item)Parameters
Section titled “Parameters”index int
The index where the item should be inserted.
item T
The object to insert.
Exceptions
Section titled “Exceptions”ReadOnlyException
If the object is read-only and the application is playing.
InsertRange(int, IEnumerable)
Section titled “InsertRange(int, IEnumerable)”Inserts the elements of a collection into the list at the specified index.
public void InsertRange(int index, IEnumerable<T> collection)Parameters
Section titled “Parameters”index int
The zero-based index at which the new elements should be inserted.
collection IEnumerable<T>
The collection whose elements should be inserted into the list.
Exceptions
Section titled “Exceptions”ArgumentNullException
If collection is null.
ArgumentOutOfRangeException
If index is less than 0 or is greater than Count.
ReadOnlyException
If the object is read-only and the application is playing.
LastIndexOf(T)
Section titled “LastIndexOf(T)”Searches for the specified object and returns the zero-based index of the last occurrence within the entire list.
public int LastIndexOf(T item)Parameters
Section titled “Parameters”item T
The object to locate in the list.
Returns
Section titled “Returns”int
The zero-based index of the last occurrence of item within the entire the list, if found; otherwise, -1.
LastIndexOf(T, int)
Section titled “LastIndexOf(T, int)”Searches for the specified object and returns the zero-based index of the last occurrence within the range of elements in the list that extends from the first element to the specified index.
public int LastIndexOf(T item, int index)Parameters
Section titled “Parameters”item T
The object to locate in the list.
index int
The zero-based starting index of the backward search.
Returns
Section titled “Returns”int
The zero-based index of the last occurrence of item within the range of elements in the list that extends from the first element to index, if found; otherwise, -1.
Exceptions
Section titled “Exceptions”ArgumentOutOfRangeException
index is outside the range of valid indexes for the list.
LastIndexOf(T, int, int)
Section titled “LastIndexOf(T, int, int)”Searches for the specified object and returns the zero-based index of the last occurrence within the range of elements in the list that contains the specified number of elements and ends at the specified index.
public int LastIndexOf(T item, int index, int count)Parameters
Section titled “Parameters”item T
The object to locate in the list.
index int
The zero-based starting index of the backward search.
count int
The number of elements in the section to search.
Returns
Section titled “Returns”int
The zero-based index of the last occurrence of item within the range of elements in the list that contains count number of elements and ends at index, if found; otherwise, -1.
Exceptions
Section titled “Exceptions”ArgumentOutOfRangeException
index is outside the range of valid indexes for the list. Or count is less than 0. Or index and count do not specify a valid section in the list.
Remove(T)
Section titled “Remove(T)”Removes the first occurrence of a specific object from the ScriptableList<T>.
public bool Remove(T item)Parameters
Section titled “Parameters”item T
The object to remove from the null for
reference types.
Returns
Section titled “Returns”bool
true if item was successfully removed from the ScriptableList<T>; otherwise, false. This method also returns false if item is not found in the original ScriptableList<T>.
Exceptions
Section titled “Exceptions”ReadOnlyException
If the object is read-only and the application is playing.
RemoveAll(Predicate)
Section titled “RemoveAll(Predicate)”Removes all the elements that match the conditions defined by the specified predicate.
public int RemoveAll(Predicate<T> match)Parameters
Section titled “Parameters”match Predicate<T>
The
Returns
Section titled “Returns”int
The number of elements removed from the ScriptableList<T>.
Exceptions
Section titled “Exceptions”ArgumentNullException
match is null.
ReadOnlyException
If the object is read-only and the application is playing.
RemoveAt(int)
Section titled “RemoveAt(int)”Removes the element at the specified index of the ScriptableList<T>.
public void RemoveAt(int index)Parameters
Section titled “Parameters”index int
The zero-based index of the element to remove.
Exceptions
Section titled “Exceptions”ArgumentOutOfRangeException
index is less than 0. -or- index is equal to or greater than Count.
ReadOnlyException
If the object is read-only and the application is playing.
RemoveRange(int, int)
Section titled “RemoveRange(int, int)”Removes a range of elements from the list.
public void RemoveRange(int index, int count)Parameters
Section titled “Parameters”index int
The zero-based starting index of the range of elements to remove.
count int
The number of elements to remove.
Exceptions
Section titled “Exceptions”ArgumentOutOfRangeException
If index is less than 0 or greater than Count.
ArgumentOutOfRangeException
If index is less than 0 or greater than Count.
ArgumentOutOfRangeException
If count is less than 0.
ArgumentException
If index and count do not denote a valid range of elements.
ReadOnlyException
If the object is read-only and the application is playing.
Reverse()
Section titled “Reverse()”Reverses the order of the elements in the entire ScriptableList<T>.
public override sealed void Reverse()Exceptions
Section titled “Exceptions”ReadOnlyException
If the object is read-only and the application is playing.
Reverse(int, int)
Section titled “Reverse(int, int)”Reverses the order of the elements in the specified range.
public override sealed void Reverse(int index, int count)Parameters
Section titled “Parameters”index int
The starting index of the range to reverse.
count int
The number of elements in the range to reverse.
Exceptions
Section titled “Exceptions”ReadOnlyException
If the object is read-only and the application is playing.
Slice(int, int)
Section titled “Slice(int, int)”Creates a shallow copy of a range of elements in the source list.
public List<T> Slice(int index, int count)Parameters
Section titled “Parameters”index int
The zero-based list index at which the range starts.
count int
The number of elements in the range.
Returns
Section titled “Returns”List<T>
A shallow copy of a range of elements in the source list.
Exceptions
Section titled “Exceptions”ArgumentOutOfRangeException
index is less than 0. Or count is less than 0.
ArgumentException
index and count do not denote a valid range of elements in the list.
Slice(int, int, IList)
Section titled “Slice(int, int, IList)”Copies a range of elements from the source list to the specified destination list.
public void Slice(int index, int count, IList<T> destinationList)Parameters
Section titled “Parameters”index int
The zero-based list index at which the range starts.
count int
The number of elements in the range.
destinationList IList<T>
The list where the copied elements will be stored.
Exceptions
Section titled “Exceptions”ArgumentNullException
destinationList is null.
ArgumentOutOfRangeException
index is less than 0. Or count is less than 0.
ArgumentException
index and count do not denote a valid range of elements in the list.
ArgumentException
destinationList is marked as read-only.
Sort(IComparer?)
Section titled “Sort(IComparer?)”Sorts the elements in the entire ScriptableList<T> using the specified comparer.
public void Sort(IComparer<T>? comparer = null)Parameters
Section titled “Parameters”comparer IComparer<T>
The null to use
the default comparer
Exceptions
Section titled “Exceptions”InvalidOperationException
comparer is null, and the default comparer cannot find an implementation of the IComparer<T> generic interface or the IComparable interface for type T.
ReadOnlyException
If the object is read-only and the application is playing.
Sort(int, int, IComparer?)
Section titled “Sort(int, int, IComparer?)”Sorts the elements in a range of elements in list using the specified comparer.
public void Sort(int index, int count, IComparer<T>? comparer = null)Parameters
Section titled “Parameters”index int
The starting index of the range to sort.
count int
The number of elements in the range to sort.
comparer IComparer<T>
The null to use
the default comparer
Exceptions
Section titled “Exceptions”InvalidOperationException
comparer is null, and the default comparer cannot find an implementation of the IComparer<T> generic interface or the IComparable interface for type T.
ReadOnlyException
If the object is read-only and the application is playing.
Sort(Comparison)
Section titled “Sort(Comparison)”Sorts the elements in the entire list using the specified Comparison<T>.
public void Sort(Comparison<T> comparison)Parameters
Section titled “Parameters”comparison Comparison<T>
The
Exceptions
Section titled “Exceptions”ArgumentNullException
comparison is null.
ReadOnlyException
If the object is read-only and the application is playing.
ToArray()
Section titled “ToArray()”Copies the elements of the ScriptableList<T> to a new array.
public T[] ToArray()Returns
Section titled “Returns”T[]
An array containing copies of the elements of the ScriptableList<T>.
TrimExcess()
Section titled “TrimExcess()”Sets the capacity to the actual number of elements in the ScriptableList<T>, if that number is less than a threshold value.
public override sealed void TrimExcess()TrueForAll(Predicate)
Section titled “TrueForAll(Predicate)”Determines whether every element in the ScriptableList<T> matches the conditions defined by the specified predicate.
public bool TrueForAll(Predicate<T> match)Parameters
Section titled “Parameters”match Predicate<T>
The
Returns
Section titled “Returns”bool
true if every element in the ScriptableList<T> matches the conditions defined by the specified predicate; otherwise, false. If the list has no elements, the return value is true.
Exceptions
Section titled “Exceptions”ArgumentNullException
match is null.
TryFind(Predicate, out T?)
Section titled “TryFind(Predicate, out T?)”Tries to find an element in the list that matches the specified predicate.
public bool TryFind(Predicate<T> match, out T? result)Parameters
Section titled “Parameters”match Predicate<T>
The
result T
The first result that matches the delegate. If no element was found, this will be the default
value.
Returns
Section titled “Returns”bool
true if an element was found; otherwise, false.
OnPreStart()
Section titled “OnPreStart()”Called when the game starts, before OnStart().
You should not subscribe to events in this method! Use OnStart() instead. OnPreStart() should be used for preparing the scriptable object.
protected override void OnPreStart()Remarks
Section titled “Remarks”If this isn’t called when the game starts, it’s called once this scriptable object is loaded and instantiated.
WarnIfLeftOverSubscribers()
Section titled “WarnIfLeftOverSubscribers()”Warns if there are any left-over subscribers to the events.
protected override void WarnIfLeftOverSubscribers()Remarks
Section titled “Remarks”This will only be called in the Unity editor and builds with the DEBUG flag.
WarnIfLeftOverObjects()
Section titled “WarnIfLeftOverObjects()”Warns if there are any left-over objects in the dictionary.
[Conditional("DEBUG")]protected void WarnIfLeftOverObjects()Remarks
Section titled “Remarks”This will only be called in the Unity editor and builds with the DEBUG flag.
ClearSubscribers(bool)
Section titled “ClearSubscribers(bool)”Removes any subscribers from the event.
public void ClearSubscribers(bool warnIfLeftOver = false)Parameters
Section titled “Parameters”warnIfLeftOver bool
If true, a warning will be printed in the console if there are any subscribers.
The warning will only be printed in the editor and debug builds.
OnDisabled()
Section titled “OnDisabled()”Called when the game is ending, after OnPreDisabled().
You should not unsubscribe from events in this method! Use OnPreDisabled() instead. OnDisabled() should be used for cleaning up the scriptable object.
protected override void OnDisabled()Remarks
Section titled “Remarks”This can also be called during the game is the scriptable object is destroyed and/or unloaded.
Events
Section titled “Events”OnCollectionChanged
Section titled “OnCollectionChanged”Occurs when an item is added, removed, replaced, or the entire ScriptableList<T> is refreshed.
public event CollectionChangedEventHandler<T>? OnCollectionChangedEvent Type
Section titled “Event Type”CollectionChangedEventHandler<T>
OnAdded
Section titled “OnAdded”Called when something was added. Gives you the newly added item.
[Obsolete("Use 'OnCollectionChanged' instead. This will be removed in build.", true)]public event Action<T>? OnAddedEvent Type
Section titled “Event Type”OnInserted
Section titled “OnInserted”Called when something was inserted. Gives you the index it was inserted at and the newly inserted item.
[Obsolete("Use 'OnCollectionChanged' instead. This will be removed in build.", true)]public event Action<int, T>? OnInsertedEvent Type
Section titled “Event Type”OnAddedOrInserted
Section titled “OnAddedOrInserted”Called when something was added or inserted. Gives you the index it was added/inserted at and the newly added/inserted item.
[Obsolete("Use 'OnCollectionChanged' instead. This will be removed in build.", true)]public event Action<int, T>? OnAddedOrInsertedEvent Type
Section titled “Event Type”Called when something was set using the indexer. Gives you the index it was set at, the old value and the new value.
[Obsolete("Use 'OnCollectionChanged' instead. This will be removed in build.", true)]public event Action<int, T, T>? OnSetEvent Type
Section titled “Event Type”OnRemoved
Section titled “OnRemoved”Called when something was removed. Gives you the index it was removed at and the removed item.
[Obsolete("Use 'OnCollectionChanged' instead. This will be removed in build.", true)]public event Action<int, T>? OnRemovedEvent Type
Section titled “Event Type”OnCleared
Section titled “OnCleared”Called when the list is cleared.
[Obsolete("Use 'OnCollectionChanged' instead. This will be removed in build.", true)]public event Action? OnClearedEvent Type
Section titled “Event Type”OnChanged
Section titled “OnChanged”Called when the list is changed in any way.
[Obsolete("Use 'OnCollectionChanged' instead. This will be removed in build.", true)]public event Action<ListChangeType>? OnChanged