Syntax Differences - T# v/s C#
This page lists everything that is currently not supported in T#
This section covers core language-level differences in T# that affect how you write basic logic, class structures, and common C# patterns. These are not Unity-specific, but general constraints imposed by the T# interpreter.
๐ง MonoBehaviour vs TerraBehaviour
In Unity, scripts connect to the engine by extending the built-in MonoBehaviour
class. This allows the script to be attached to GameObjects and use lifecycle methods like Start()
and Update()
. T# scripts , however, don't inherit from the Monobehaviour
Class.
In T#, do not inherit from MonoBehaviour
. It is unsupported and will prevent your script from working.
๐ What you instead need to do in T#:
All scripts must derive from TerraBehaviour
( (or TerraNetBehaviour
in case of multiplayer games) instead of MonoBehaviour
. This is the base class recognized by Terra Studioโs runtime for regular game scripts.
All scripts in T# must inherit from either TerraBehaviour
(for single-player logic) or TerraNetBehaviour
(for multiplayer features), depending on the game type.
๐ ๏ธ Default Variable Assigning
In Unity, it's common (and convenient) to assign default values to variables directly when declaring them. However, this pattern is not supported in T# if the value is assigned outside a method.
๐ What you instead need to do in T# to avoid inline assignment:
Always initialize variables inside a method like Start()
.
๐๏ธ Serialized Fields
In Unity, developers often use public
or [SerializeField]
fields to expose values in the Inspector. This lets you easily assign GameObjects, floats, and other data through the Unity Editor.This allows you to assign values directly in the Unity Editor but this method isn't supported in T#.
๐ What you instead need to do in T# to access Inspector-like values:
T# doesnโt support public
fields or [SerializeField]
. Use built-in variable getter methods instead.
๐ Instead, use the built-in variable getters like the following:
GetObjectVariable(string name)
Gets GameObject variable with the specified name
GetIntVariable(string name)
Gets integer variable with the specified name
GetFloatVariable(string name)
Gets float variable with the specified name
GetBoolVariable(string name)
Gets boolean variable with the specified name
GetCurveVariable(string name)
Gets AnimationCurve variable with the specified name
๐งฌ Generic Methods
Unity supports generic methods like GetComponent<T>()
, AddComponent<T>()
, and FindObjectOfType<T>()
for flexible and type-safe component handling. These are popular for writing clean, reusable code. However, Generic versions of Unity methods like GetComponent<T>
, AddComponent<T>
, FindObjectOfType<T>
, and similar methods involving generics are not supported in T#.
None of the following generic methods are supported. Using them will always throw up an error
๐ What you instead need to do in T# to work with components:
Instead, in T#, non-generic alternatives should be used such as the following:
๐ฎ Enums
In Unity, developers often use enum
to define named states or categories for readability and cleaner switch logic.This is not supported in T#.
๐ What you instead need to do in T# to represent states:
Use constants (int
or string
) to represent each state.
๐ Switch
In Unity, switch
statements are a clean way to handle multiple branches based on an integer, enum, or string value. This is not supported in T#.
๐ What you instead need to do in T#:
Use if-else
chains to replicate switch behavior.
๐ foreach
Loops
foreach
Loopsforeach
is a clean and readable way to iterate over children or elements in a collection without worrying about indexing. Itโs especially popular when working with Transform
, GameObject
, or any IEnumerable
. However, foreach
is not supported in T#.
๐ What you instead need to do in T# to avoid foreach
:
T# currently doesnโt support foreach
, so always use a classic for
loop when working with collections or child transforms.
Last updated