# Unity C# to GDScript: the API map

Most of a Unity script maps to Godot 4 one call at a time, but few calls are a plain rename: a MonoBehaviour becomes a script on the node it describes, GetComponent becomes a node path, a coroutine becomes await, a trigger callback becomes a signal, and Godot looks down −Z where Unity looks down +Z. The map below gives each one in GDScript, every line run on Godot 4.7.2.

Source: https://flockbay.com/unity-csharp-to-gdscript/ · Updated 2026-11-08

## Random.Range(0, 10) never returns 10, and randi_range(0, 10) does

Start with the line that breaks most often after a port. In Unity, Random.Range with two integers leaves out the top: Random.Range(0, 10) gives 0 to 9. Godot's randi_range(0, 10) includes it. Run it 2,000 times on Godot 4.7.2 and it reaches 10; randi() % 10 tops out at 9. A loot table or a spawn index ported word for word is off by one, and nothing errors.

That is the shape of the whole port. Almost every Unity call has a Godot answer, and the ones that look identical are where a rebuilt game quietly drifts. The sections below go system by system, and each GDScript line was run on the Godot 4.7.2 that Flockbay ships.

```
var index := randi_range(0, 9)  # Random.Range(0, 10) with ints
var roll := randf_range(0.0, 1.0)  # Random.Range(0f, 1f) and Random.value
```

## A MonoBehaviour becomes a script on the node it describes

Unity hangs behaviour on an empty GameObject as components. Godot has no empty container: the script extends the node type it is, so a player script that moved a Rigidbody2D by hand extends CharacterBody2D, and an enemy that only draws extends Node2D.

Start and the first Awake work become _ready. Update becomes _process(delta), FixedUpdate becomes _physics_process(delta), and LateUpdate becomes _process on a node whose process_priority is higher. OnDestroy becomes _exit_tree. OnEnable and OnDisable have no single twin: watch NOTIFICATION_ENABLED and NOTIFICATION_DISABLED in _notification, or visibility_changed for a hidden node.

Awake is the trap. Godot calls a child's _ready before its parent's, so a parent that set something up in Awake for its children to read in Start must move that work to _init or _enter_tree, which run top down.

```
extends CharacterBody2D

@export var speed: float = 500.0  # [SerializeField] float speed = 5f, at 100 pixels per unit

func _ready() -> void:  # Start
	pass

func _physics_process(delta: float) -> void:  # FixedUpdate
	velocity.x = Input.get_axis("move_left", "move_right") * speed
	move_and_slide()
```

## GetComponent becomes a node path, a typed child or an export

GetComponent<T>() asks a GameObject for a component it carries. In Godot the thing you want is a node in the tree, so you name it: get_node("Sprite2D"), $Sprite2D for short, or an @export var of that type that you drag in, which survives renames. find_child searches below a node when the path is not fixed.

FindObjectOfType has no engine-wide search. Put the node in a group (add_to_group("enemies"), or the Node dock's Groups tab) and ask the tree: get_first_node_in_group("enemies") for one, get_nodes_in_group("enemies") for all of them. On Godot 4.7.2 a script that adds itself in _ready is found by both.

```
var sprite: Sprite2D = $Sprite2D  # GetComponent<SpriteRenderer>()
var boss := get_tree().get_first_node_in_group("enemies")  # FindObjectOfType<Enemy>()
for enemy in get_tree().get_nodes_in_group("enemies"):  # FindObjectsOfType<Enemy>()
	enemy.take_damage(10)
```

## Coroutines become await, and DOTween becomes a Tween

yield return new WaitForSeconds(t) becomes await get_tree().create_timer(t).timeout, inside any function; there is no StartCoroutine to call. yield return null, one frame, is await get_tree().process_frame. A coroutine you stopped with StopCoroutine is a function that checks a flag after each await.

DOTween's transform.DOMove(target, 0.2f) is create_tween().tween_property(self, "position", target, 0.2). On Godot 4.7.2 a 0.2-second tween of a Node2D to (100, 0) finishes exactly there, and await tween.finished waits for it.

```
await get_tree().create_timer(0.5).timeout  # yield return new WaitForSeconds(0.5f)
var tween := create_tween()  # transform.DOMove(target, 0.2f)
tween.tween_property(self, "position", Vector2(100, 0), 0.2)
await tween.finished
```

## Instantiate is instantiate(), and Destroy is queue_free()

A prefab is a scene file. Instantiate(prefab) becomes load or preload the .tscn, call instantiate() and add_child the result; Destroy(gameObject) becomes queue_free(), which frees the node at the end of the frame.

A DontDestroyOnLoad singleton becomes an autoload: a scene or script listed in Project Settings > Globals that lives above every scene. SceneManager.LoadScene("Level2") becomes get_tree().change_scene_to_file("res://level_2.tscn").

A UnityEvent becomes a signal: declare it with signal died, call died.emit(), and connect a callable. On Godot 4.7.2 an enemy that emits died and then calls queue_free is heard by its listener and gone by the next frame.

```
const BULLET := preload("res://bullet.tscn")  # the prefab

func fire() -> void:
	var bullet := BULLET.instantiate()  # Instantiate(bulletPrefab)
	get_parent().add_child(bullet)

signal died  # public UnityEvent onDied

func take_damage(amount: int) -> void:
	health -= amount
	if health <= 0:
		died.emit()  # onDied.Invoke()
		queue_free()  # Destroy(gameObject)
```

## Input reads named actions, not axes and key codes

Unity's Input Manager has axes (Horizontal, Vertical) and buttons (Jump, Fire1). Godot has actions in Project Settings > Input Map, each a list of keys, buttons and stick directions. Input.GetAxis("Horizontal") becomes Input.get_axis("move_left", "move_right"), two actions for the two directions; GetButtonDown becomes Input.is_action_just_pressed, GetButton is_action_pressed, GetButtonUp is_action_just_released.

Unity's vertical axis is positive up. In Godot 2D, y grows downward, so negate it before you move: velocity.y = -Input.get_axis("move_down", "move_up") * speed, or define the actions the other way round. Input.get_vector("move_left", "move_right", "move_up", "move_down") gives a 2D direction already in Godot's orientation.

The new Input System's action maps are the closest match: each action becomes one Godot action, and an action's bindings become its events.

```
var direction := Input.get_vector("move_left", "move_right", "move_up", "move_down")
if Input.is_action_just_pressed("jump"):  # Input.GetButtonDown("Jump")
	velocity.y = -jump_speed
```

## Physics callbacks become signals you connect

OnTriggerEnter is an Area3D or Area2D's body_entered signal. OnCollisionEnter is a RigidBody's body_entered, which only fires with contact_monitor on and max_contacts_reported above 0. A Rigidbody's velocity is linear_velocity; AddForce is apply_central_force, and ForceMode.Impulse is apply_central_impulse. CharacterController.Move is a CharacterBody3D's velocity and move_and_slide().

Physics.Raycast is a query on the world's physics space: PhysicsRayQueryParameters3D.create(from, to), passed to get_world_3d().direct_space_state.intersect_ray. It answers a dictionary with the collider, position and normal, and an empty dictionary when nothing was hit. A RayCast3D node does the same every physics frame.

```
func _ready() -> void:
	$Area3D.body_entered.connect(_on_body_entered)  # OnTriggerEnter

func _on_body_entered(body: Node3D) -> void:
	print("entered: ", body.name)

func ground_below() -> Dictionary:  # Physics.Raycast
	var query := PhysicsRayQueryParameters3D.create(global_position, global_position + Vector3.DOWN * 10.0)
	return get_world_3d().direct_space_state.intersect_ray(query)
```

## Godot looks down −Z, unless the scene came from Unity

Unity's transform.forward is +Z. Godot's forward is −Z: -global_transform.basis.z, and Vector3.FORWARD is (0, 0, −1). look_at(target, Vector3.UP) turns a node's −Z toward the target. Written for a Godot scene, a Unity forward becomes -basis.z.

A scene converted from Unity is different. Importers that bring Unity scenes into Godot, such as the open-source Unidot Importer, mirror the x axis so a Unity position (x, y, z) lands at (−x, y, z), and the model still faces +Z. In such a scene transform.forward is global_transform.basis.z, transform.right is -global_transform.basis.x, Vector3.forward is Vector3(0, 0, 1) (Godot's Vector3.BACK), and LookAt is look_at(target, Vector3.UP, true), whose last argument turns +Z toward the target. On Godot 4.7.2 both calls face the way their comments say.

```
# A scene built in Godot
var ahead := -global_transform.basis.z  # transform.forward
look_at(target, Vector3.UP)  # transform.LookAt(target)

# A scene converted from Unity with x mirrored
var ahead_imported := global_transform.basis.z
look_at(target, Vector3.UP, true)
```

## Time, math, logs and saves are built in

Time.deltaTime is the delta argument of _process and _physics_process. Time.time is Time.get_ticks_msec() / 1000.0. Mathf.Lerp, Clamp, Abs and MoveTowards are the global lerp, clamp, abs and move_toward. Debug.Log is print, Debug.LogWarning push_warning, Debug.LogError push_error.

PlayerPrefs becomes a ConfigFile saved in user://, the per-user folder Godot gives every game. On Godot 4.7.2 a value saved and loaded back that way reads 42.

```
var prefs := ConfigFile.new()  # PlayerPrefs.SetInt("best", 42); PlayerPrefs.Save()
prefs.set_value("scores", "best", 42)
prefs.save("user://prefs.cfg")

var loaded := ConfigFile.new()  # PlayerPrefs.GetInt("best", 0)
loaded.load("user://prefs.cfg")
var best: int = loaded.get_value("scores", "best", 0)
```

## A ScriptableObject is a Resource, and an attribute is an annotation

A ScriptableObject is a class that extends Resource with a class_name, saved as a .tres you edit in the Inspector and load anywhere. [SerializeField] is @export, [Header("Movement")] is @export_group("Movement"), [Range(0, 100)] is @export_range(0, 100), and [HideInInspector] is a plain var.

Animator.SetTrigger, SetBool and SetFloat become the AnimationTree's parameters: set("parameters/conditions/jump", true), or travel to a state through its playback. AudioSource.Play is an AudioStreamPlayer's play(). A TextMeshProUGUI's text is a Label's text, and an Image is a TextureRect.

```
class_name EnemyStats
extends Resource  # : ScriptableObject

@export_group("Movement")  # [Header("Movement")]
@export var speed: float = 500.0  # [SerializeField]
@export_range(0, 100) var health: int = 100  # [Range(0, 100)]
```

## In 2D, units become pixels and y points down

Unity 2D measures in units, and a sprite's Pixels Per Unit says how many pixels one unit is. Godot 2D measures in pixels with y growing downward. Multiply positions, speeds, forces and gravity by the pixels per unit, negate y, and negate angles: at Unity's default 100, a speed of 5 becomes 500 and a jump velocity of 8 becomes -800.

transform.right is global_transform.x and transform.up is -global_transform.y. A SpriteRenderer's sortingOrder becomes the Sprite2D's z_index.

## Questions

### Is there a tool that converts Unity C# to GDScript?

Not one that turns a real script into working GDScript unattended: the Unity API underneath has to be rewritten call by call, which is what this map is for. Flockbay's Import from Unity hands each script to an AI with its Unity source and the converted scene beside it, and the AI runs the result, since the calls that look identical are the ones that drift.

### Can I keep my C# in Godot?

Godot's .NET build runs C#, but against Godot's API, not Unity's, so every MonoBehaviour is rewritten either way. Flockbay's Godot runs C# on Windows and Linux; on macOS it runs GDScript.

### What is Update in Godot?

_process(delta) runs every frame, like Update. _physics_process(delta) runs at the fixed physics rate, like FixedUpdate.

### What replaces GetComponent in Godot?

A node reference: get_node("Name"), its short form $Name, or an @export variable of the node's type. A group and get_first_node_in_group replace FindObjectOfType.

Download Flockbay free: Flockbay's AI rewrites Unity scripts for Godot 4 with this map and runs the game to check them, on Windows, macOS or Linux. https://flockbay.com/

Related: [Unity to Godot](/unity-to-godot/), [Use your Unity Asset Store assets in Godot](/unity-asset-store-to-godot/), [What is GDScript?](/what-is-gdscript/), [yield is await](/godot/wait-in-godot-4-await-instead-of-yield/)
