Restrictions on Collections & Types
This page lists everything that is currently not supported in T#
T# does not fully support complex C# data types like Dictionary
, List<T>
, or user-defined script collections.This section lists the type system differences and shows how to work with Terra-compatible collections instead
๐งพ Dictionaries
In Unity, Dictionary<TKey, TValue>
is used to store and quickly access data using keys โ it's a common tool for lookups, mapping, and efficient access patterns. This pattern is not supported in T#.
Dictionary<string, int> myDict = new Dictionary<string, int>();
๐ What you instead need to do in T# to use key-value pairs:
Use TerraDictionary
, which is interpreter-compatible.
TerraDictionary myDict = new TerraDictionary();
myDict.Add("key1", 1);
int value = (int)myDict["key1"]; // โ
Works
๐ Lists
In Unity, List<T>
is the go-to for dynamic arrays โ it's used to manage growing or shrinking collections of elements like GameObjects, positions, and more. This approach is not supported in T#.
List<float> myList = new List<float>();
myList.Add(1.5f);
float firstItem = myList[0];
๐ What you instead need to do in T# to work with dynamic collections:
Use TerraList
, which works the same way but is compatible with T#.
TerraList myList = new TerraList();
myList.Add(5);
int firstInt = (int)myList[0];
TerraList gameObjectList = new TerraList();
gameObjectList.Add(someGameObject);
GameObject firstObject = (GameObject)gameObjectList[0];
๐ฆ Structs in TerraList
In Unity, structs are often used for lightweight data containers, and itโs common to store them in collections. This is not supported in T#.
TerraList structList = new TerraList();
structList.Add(new MyStruct()); // โ
๐ What you instead need to do in T#:
Avoid storing custom structs in TerraList
.Only primitive types (like int
, float
, bool
) or supported objects (e.g., GameObject
) should be added.
๐งฉ Custom Scripts in Collections
In Unity, it's common to store custom script instances inside List<T>
or Dictionary<TKey, TValue>
for managing multiple game behaviors. This is not supported in T#.
List<MyCustomScript> scriptList = new List<MyCustomScript>();
Dictionary<string, MyCustomScript> scriptDict = new Dictionary<string, MyCustomScript>();
๐ What you instead need to do in T#:
Use GameObject
references and access the components as needed.
List<GameObject> objectList = new List<GameObject>();
MyCustomScript script = objectList[0].GetComponent(typeof(MyCustomScript)) as MyCustomScript;
๐งฎ LINQ Libraries
Unity developers often use LINQ (.Where()
, .ToList()
, etc.) for elegant data filtering and querying collections. This is not supported in T#.
var filtered = myList.Where(x => x > 5).ToList();
๐ What you instead need to do in T#: Use traditional loops to filter or transform data.
List<int> filtered = new List<int>();
for (int i = 0; i < myList.Count; i++) {
if (myList[i] > 5) {
filtered.Add(myList[i]);
}
}
Last updated