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