Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

C# API と GDScript の違い

これは、C#とGDScriptのAPIの相違点の(不完全な)リストです。

一般的な相違点

C#とGDScriptの一般的な違い で説明されているように、C# で Godot API にアクセスするには、GDScript/C++の snake_case の代わりに PascalCase を使います。 可能な場合はフィールドとゲッター/セッターはプロパティに変換されています。一般的に C# Godot APIは合理的に可能な限り慣用的であるように努めています。C# スタイルガイド を参照してください。独自の C# コードにもこれを使用することをお勧めします。

GDScript ではプロパティのセッター/ゲッターを直接呼び出すことができますが、これは推奨されていません。C# ではプロパティのみが定義されます。たとえば、GDScript コード x.set_name("Friend") を C# に変換するには x.Name = "Friend"; と記述します。

C# の IDE は名前が変更された C# API を理解するときに非常に便利なインテリセンスを提供します。組み込みの Godot スクリプト エディタは C# インテリセンスをサポートしておらず、必須と見なされる他の多くの C# 開発ツールも提供していません。 外部エディタの設定 を参照してください。

グローバル スコープ

C#では名前空間で宣言できないため、グローバル関数と一部の定数をクラスに移動する必要がありました。ほとんどのグローバル定数は、独自の列挙型に移動されました。

定数

C# では定数にできるのはプリミティブ型のみです。たとえば、定数 TAU は定数 Mathf.Tau に置き換えられますが、定数 Vector2.RIGHT は読み取り専用プロパティ Vector2.Right に置き換えられます。これは定数と同様に動作しますが、 switch ステートメントなどの一部のコンテキストでは使用できません。

グローバル列挙定数は、独自の列挙に移動されました。たとえば ERR_* 定数は Error 列挙型に移動されました。

特殊なケース:

GDScript

C#

TYPE_*

Variant.Type 列挙型

OP_*

Variant.Operator 列挙型

数学関数

absacosasinatanatan2 などの数学グローバル関数は、Mathf の下に AbsAcosAsinAtan および Atan2``として、\ ``PI 定数は Mathf.Pi として見つけることができます。

C# には他の便利な数学演算を含む静的な System.Math クラスと System.MathF クラスも用意されています。

乱数生成関数

rand_rangerand_seed などの乱数生成用のグローバル関数は、GD の下にあります。例:GD.RandRange および GD.RandSeed

System.Random の使用を検討してください。暗号的に強力なランダム性が必要な場合は、System.Security.Cryptography.RandomNumberGenerator を使用してください。

その他の関数

printvar_to_str などの他の多くのグローバル関数は GD の下にあります。例: GD.Print および GD.VarToStr

例外:

GDScript

C#

weakref(obj)

GodotObject.WeakRef(obj)

instance_from_id(id)

GodotObject.InstanceFromId(id)

is_instance_id_valid(id)

GodotObject.IsInstanceIdValid(id)

is_instance_valid(obj)

GodotObject.IsInstanceValid(obj)

ヒント

using static ディレクティブを使用すると便利な場合があります。このディレクティブにより、クラス名を指定せずに、クラスのメンバーおよびネストされたタイプにアクセスできます。

例:

using static Godot.GD;

public class Test
{
    static Test()
    {
        Print("Hello"); // Instead of GD.Print("Hello");
    }
}

APIの対応表

Godot のグローバルスコープ関数とそれに対応する C# 関数の一覧です:

GDScript

C#

abs

Mathf.Abs

absf

Mathf.Abs

absi

Mathf.Abs

acos

Mathf.Acos

acosh

Mathf.Acosh

angle_difference

Mathf.AngleDifference

asin

Mathf.Asin

asinh

Mathf.Asinh

atan

Mathf.Atan

atan2

Mathf.Atan2

atanh

Mathf.Atanh

bezier_derivative

Mathf.BezierDerivative

bezier_interpolate

Mathf.BezierInterpolate

bytes_to_var

GD.BytesToVar

bytes_to_var_with_objects

GD.BytesToVarWithObjects

ceil

Mathf.Ceil

ceilf

Mathf.Ceil

ceili

Mathf.CeilToInt

clamp

Mathf.Clamp

clampf

Mathf.Clamp

clampi

Mathf.Clamp

cos

Mathf.Cos

cosh

Mathf.Cosh

cubic_interpolate

Mathf.CubicInterpolate

cubic_interpolate_angle

Mathf.CubicInterpolateAngle

cubic_interpolate_angle_in_time

Mathf.CubicInterpolateInTime

cubic_interpolate_in_time

Mathf.CubicInterpolateAngleInTime

db_to_linear

Mathf.DbToLinear

deg_to_rad

Mathf.DegToRad

ease

Mathf.Ease

error_string

Error.ToString

exp

Mathf.Exp

floor

Mathf.Floor

floorf

Mathf.Floor

floori

Mathf.FloorToInt

fmod

operator %

fposmod

Mathf.PosMod

hash

GD.Hash

instance_from_id

GodotObject.InstanceFromId

inverse_lerp

Mathf.InverseLerp

is_equal_approx

Mathf.IsEqualApprox

is_finite

Mathf.IsFinite or float.IsFinite or double.IsFinite

is_inf

Mathf.IsInf or float.IsInfinity or double.IsInfinity

is_instance_id_valid

GodotObject.IsInstanceIdValid

is_instance_valid

GodotObject.IsInstanceValid

is_nan

Mathf.IsNaN or float.IsNaN or double.IsNaN

is_same

operator == or object.ReferenceEquals

is_zero_approx

Mathf.IsZeroApprox

lerp

Mathf.Lerp

lerp_angle

Mathf.LerpAngle

lerpf

Mathf.Lerp

linear_to_db

Mathf.LinearToDb

log

Mathf.Log

max

Mathf.Max

maxf

Mathf.Max

maxi

Mathf.Max

min

Mathf.Min

minf

Mathf.Min

mini

Mathf.Min

move_toward

Mathf.MoveToward

nearest_po2

Mathf.NearestPo2

pingpong

Mathf.PingPong

posmod

Mathf.PosMod

pow

Mathf.Pow

print

GD.Print

print_rich

GD.PrintRich

print_verbose

Use OS.IsStdoutVerbose and GD.Print

printerr

GD.PrintErr

printraw

GD.PrintRaw

prints

GD.PrintS

printt

GD.PrintT

push_error

GD.PushError

push_warning

GD.PushWarning

rad_to_deg

Mathf.RadToDeg

rand_from_seed

GD.RandFromSeed

randf

GD.Randf

randf_range

GD.RandRange

randfn

GD.Randfn

randi

GD.Randi

randi_range

GD.RandRange

randomize

GD.Randomize

remap

Mathf.Remap

rid_allocate_id

N/A

rid_from_int64

N/A

rotate_toward

Mathf.RotateToward

round

Mathf.Round

roundf

Mathf.Round

roundi

Mathf.RoundToInt

seed

GD.Seed

sign

Mathf.Sign

signf

Mathf.Sign

signi

Mathf.Sign

sin

Mathf.Sin

sinh

Mathf.Sinh

smoothstep

Mathf.SmoothStep

snapped

Mathf.Snapped

snappedf

Mathf.Snapped

snappedi

Mathf.Snapped

sqrt

Mathf.Sqrt

step_decimals

Mathf.StepDecimals

str

Use $ string interpolation

str_to_var

GD.StrToVar

tan

Mathf.Tan

tanh

Mathf.Tanh

type_convert

Variant.As<T> or GD.Convert

type_string

Variant.Type.ToString

typeof

Variant.VariantType

var_to_bytes

GD.VarToBytes

var_to_bytes_with_objects

GD.VarToBytesWithObjects

var_to_str

GD.VarToStr

weakref

GodotObject.WeakRef

wrap

Mathf.Wrap

wrapf

Mathf.Wrap

wrapi

Mathf.Wrap

GDScript ユーティリティ関数とそれに対応する C# 関数の一覧:

GDScript

C#

assert

System.Diagnostics.Debug.Assert

char

明示的な変換を使用します: (char)65

convert

GD.Convert

dict_to_inst

N/A

get_stack

System.Environment.StackTrace

inst_to_dict

N/A

len

N/A

load

GD.Load

preload

N/A

print_debug

N/A

print_stack

GD.Print(System.Environment.StackTrace)

range

GD.Range or System.Linq.Enumerable.Range

type_exists

ClassDB.ClassExists(type)

GDScriptで動作する preload は、C#では使用できません。代わりに GD.Load または ResourceLoader.Load を使用してください。

@export アノテーション

GDScriptの @export アノテーションの代わりに [Export] 属性を使用します。この属性は、オプションの PropertyHint および hintString パラメーターで提供することもできます。デフォルト値は、値を割り当てることで設定できます。

例:

using Godot;

public partial class MyNode : Node
{
    [Export]
    private NodePath _nodePath;

    [Export]
    private string _name = "default";

    [Export(PropertyHint.Range, "0,100000,1000,or_greater")]
    private int _income;

    [Export(PropertyHint.File, "*.png,*.jpg")]
    private string _icon;
}

C# exported properties も参照してください。

signal キーワード

GDScript の signal キーワードの代わりに [Signal] 属性を使用してシグナルを宣言します。この属性は、シグナルを定義するために名前の署名を使用する delegate で使用する必要があります。delegate には EventHandler サフィックスが必要です。クラス内に同じ名前でサフィックスなしの event が生成されます。そのイベントの名前を EmitSignal で使用します。

[Signal]
delegate void MySignalEventHandler(string willSendAString);

C#シグナル も参照して下さい。

@onready アノテーション

GDScript には @onready で ready 関数が呼び出されるまでメンバ変数の初期化を延期させる機能があります (cf. @onready アノテーション)。例:

@onready var my_label = get_node("MyLabel")

ただし、C# にはこの機能がありません。同じ効果を得るには、次の操作を行う必要があります。

private Label _myLabel;

public override void _Ready()
{
    _myLabel = GetNode<Label>("MyLabel");
}

シングルトン

シングルトンは、シングルトンパターンを使用するのではなく、静的クラスとして使用できます。これは、コードを Instance プロパティを使用する場合よりも冗長にするためです。

例:

Input.IsActionPressed("ui_down")

ただし非常にまれなケースでは、これでは不十分です。たとえば Connect のように、基本クラス GodotObject のメンバーにアクセスしたい場合があります。このようなユースケースでは、シングルトンインスタンスを返す Singleton という静的プロパティが用意されています。このインスタンスの型は GodotObject です。

例:

Input.Singleton.JoyConnectionChanged += Input_JoyConnectionChanged;

If you are developing main screen plugins, it is essential to note that EditorInterface is not a static class in C#, unlike in GDScript. Therefore, you must use the singleton pattern to obtain an instance of the EditorInterface:

GDScript

C#

EditorInterface

EditorInterface.Singleton

文字列

System.String (string) を使用します。Godot の String メソッドのほとんどは System.String に同等のものが存在するか、または StringExtensions クラスによって拡張メソッドとして提供されています。

例:

string text = "Get up!";
string[] bigrams = text.Bigrams(); // ["Ge", "et", "t ", " u", "up", "p!"]

.NET では文字列はイミュータブル(不変)であるため、文字列を操作するすべてのメソッドは元の文字列を変更せず、変更を適用した新しく作成された文字列を返します。複数の文字列割り当てを作成しないようにするには、StringBuilder の使用を検討してください。

Godot の String メソッドと C# の同等メソッドの対応表:

GDScript

C#

begins_with

string.StartsWith

bigrams

StringExtensions.Bigrams

bin_to_int

StringExtensions.BinToInt

c_escape

StringExtensions.CEscape

c_unescape

StringExtensions.CUnescape

capitalize

StringExtensions.Capitalize

casecmp_to

StringExtensions.CasecmpTo or StringExtensions.CompareTo (string.Equals or string.Compare の使用を検討してください)

chr

N/A

contains

string.Contains

count

StringExtensions.Count (RegEx の使用を検討してください)

countn

StringExtensions.CountN (RegEx の使用を検討してください)

dedent

StringExtensions.Dedent

ends_with

string.EndsWith

erase

string.Remove (文字列を操作するには StringBuilder の使用を検討してください)

find

StringExtensions.Find (string.IndexOf or string.IndexOfAny の使用を検討してください)

findn

StringExtensions.FindN (string.IndexOf or string.IndexOfAny の使用を検討してください)

format

Use $ string interpolation

get_base_dir

StringExtensions.GetBaseDir

get_basename

StringExtensions.GetBaseName

get_extension

StringExtensions.GetExtension

get_file

StringExtensions.GetFile

get_slice

N/A

get_slice_count

N/A

get_slicec

N/A

hash

StringExtensions.Hash (GDScriptと同じ動作を保証する必要がない限り、object.GetHashCode の使用を検討してください。)

hex_decode

StringExtensions.HexDecode (System.Convert.FromHexString の使用を検討してください)

hex_to_int

StringExtensions.HexToInt (int.Parse or long.Parse with System.Globalization.NumberStyles.HexNumber の使用を検討してください)

humanize_size

N/A

indent

StringExtensions.Indent

insert

string.Insert (文字列を操作するには StringBuilder の使用を検討してください)

is_absolute_path

StringExtensions.IsAbsolutePath

is_empty

string.IsNullOrEmpty or string.IsNullOrWhiteSpace

is_relative_path

StringExtensions.IsRelativePath

is_subsequence_of

StringExtensions.IsSubsequenceOf

is_subsequence_ofn

StringExtensions.IsSubsequenceOfN

is_valid_filename

StringExtensions.IsValidFileName

is_valid_float

StringExtensions.IsValidFloat (Consider using float.TryParse or double.TryParse)

is_valid_hex_number

StringExtensions.IsValidHexNumber

is_valid_html_color

StringExtensions.IsValidHtmlColor

is_valid_identifier

StringExtensions.IsValidIdentifier

is_valid_int

StringExtensions.IsValidInt (int.TryParse or long.TryParse の使用を検討してください)

is_valid_ip_address

StringExtensions.IsValidIPAddress

join

string.Join

json_escape

StringExtensions.JSONEscape

left

StringExtensions.Left (string.Substring or string.AsSpan の使用を検討してください)

length

string.Length

lpad

string.PadLeft

lstrip

string.TrimStart

match

StringExtensions.Match (RegEx の使用を検討してください)

matchn

StringExtensions.MatchN (RegEx の使用を検討してください)

md5_buffer

StringExtensions.Md5Buffer (System.Security.Cryptography.MD5.HashData の使用を検討してください)

md5_text

StringExtensions.Md5Text (System.Security.Cryptography.MD5.HashData with `StringExtensions.HexEncode`_ の使用を検討してください)

naturalnocasecmp_to

N/A (string.Equals or string.Compare の使用を検討してください)

nocasecmp_to

StringExtensions.NocasecmpTo or StringExtensions.CompareTo (string.Equals or string.Compare の使用を検討してください)

num

float.ToString or double.ToString

num_int64

int.ToString or long.ToString

num_scientific

float.ToString or double.ToString

num_uint64

uint.ToString or ulong.ToString

pad_decimals

StringExtensions.PadDecimals

pad_zeros

StringExtensions.PadZeros

path_join

StringExtensions.PathJoin

repeat

stringコンストラクタ または StringBuilder を使用します

replace

string.Replace or RegEx

replacen

StringExtensions.ReplaceN (string.Replace or RegEx の使用を検討してください)

reverse

N/A

rfind

StringExtensions.RFind (string.LastIndexOf or string.LastIndexOfAny の使用を検討してください)

rfindn

StringExtensions.RFindN (string.LastIndexOf or string.LastIndexOfAny の使用を検討してください)

right

StringExtensions.Right (string.Substring or string.AsSpan の使用を検討してください)

rpad

string.PadRight

rsplit

N/A

rstrip

string.TrimEnd

sha1_buffer

StringExtensions.Sha1Buffer (System.Security.Cryptography.SHA1.HashData の使用を検討してください)

sha1_text

StringExtensions.Sha1Text (System.Security.Cryptography.SHA1.HashData with `StringExtensions.HexEncode`_ の使用を検討してください)

sha256_buffer

StringExtensions.Sha256Buffer (System.Security.Cryptography.SHA256.HashData の使用を検討してください)

sha256_text

StringExtensions.Sha256Text (System.Security.Cryptography.SHA256.HashData with `StringExtensions.HexEncode`_ の使用を検討してください)

similarity

StringExtensions.Similarity

simplify_path

StringExtensions.SimplifyPath

split

StringExtensions.Split (string.Split の使用を検討してください)

split_floats

StringExtensions.SplitFloat

strip_edges

StringExtensions.StripEdges (string.Trim, string.TrimStart or string.TrimEnd の使用を検討してください)

strip_escapes

StringExtensions.StripEscapes

substr

StringExtensions.Substr (string.Substring or string.AsSpan の使用を検討してください)

to_ascii_buffer

StringExtensions.ToAsciiBuffer (System.Text.Encoding.ASCII.GetBytes の使用を検討してください)

to_camel_case

StringExtensions.ToCamelCase

to_float

StringExtensions.ToFloat (float.TryParse or double.TryParse の使用を検討してください)

to_int

StringExtensions.ToInt (int.TryParse or long.TryParse の使用を検討してください)

to_lower

string.ToLower

to_pascal_case

StringExtensions.ToPascalCase

to_snake_case

StringExtensions.ToSnakeCase

to_upper

string.ToUpper

to_utf16_buffer

StringExtensions.ToUtf16Buffer (System.Text.Encoding.UTF16.GetBytes の使用を検討してください)

to_utf32_buffer

StringExtensions.ToUtf32Buffer (System.Text.Encoding.UTF32.GetBytes の使用を検討してください)

to_utf8_buffer

StringExtensions.ToUtf8Buffer (System.Text.Encoding.UTF8.GetBytes の使用を検討してください)

to_wchar_buffer

Windows では StringExtensions.ToUtf16Buffer、その他のプラットフォームでは StringExtensions.ToUtf32Buffer

trim_prefix

StringExtensions.TrimPrefix

trim_suffix

StringExtensions.TrimSuffix

unicode_at

string[int] インデクサー

uri_decode

StringExtensions.URIDecode (System.Uri.UnescapeDataString の使用を検討してください)

uri_encode

StringExtensions.URIEncode (System.Uri.EscapeDataString の使用を検討してください)

validate_node_name

StringExtensions.ValidateNodeName

xml_escape

StringExtensions.XMLEscape

xml_unescape

StringExtensions.XMLUnescape

文字列を作成する Godot の PackedByteArray メソッドとそれに対応する C# のリスト:

GDScript

C#

get_string_from_ascii

StringExtensions.GetStringFromAscii (System.Text.Encoding.ASCII.GetString の使用を検討してください)

get_string_from_utf16

StringExtensions.GetStringFromUtf16 (System.Text.Encoding.UTF16.GetString の使用を検討してください)

get_string_from_utf32

StringExtensions.GetStringFromUtf32 (System.Text.Encoding.UTF32.GetString の使用を検討してください)

get_string_from_utf8

StringExtensions.GetStringFromUtf8 (System.Text.Encoding.UTF8.GetString の使用を検討してください)

hex_encode

StringExtensions.HexEncode (System.Convert.ToHexString の使用を検討してください)

注釈

.NET は System.IO.Path クラスの下にパス ユーティリティ メソッドを提供します。これらはネイティブ OS パスでのみ使用でき、Godot パス (res:// または user:// で始まるパス) では使用できません。Godotプロジェクトのファイルパス を参照してください。

NodePath

次のメソッドは、異なる名前のプロパティに変換されました:

GDScript

C#

is_empty()

IsEmpty

シグナル

次のメソッドは、それぞれの名前が変更されたプロパティに変換されました:

GDScript

C#

get_name()

Name

get_object()

Owner

The Signal type implements the awaitable pattern which means it can be used with the await keyword. See await keyword.

Instead of using the Signal type, the recommended way to use Godot signals in C# is to use the generated C# events. See C#シグナル.

Callable

次のメソッドは、それぞれの名前が変更されたプロパティに変換されました:

GDScript

C#

get_object()

Target

get_method()

Method

Currently C# supports Callable if one of the following holds:

  • Callable was created using the C# Callable type.

  • Callable is a basic version of the engine's Callable. Custom Callables are unsupported. A Callable is custom when any of the following holds:

    • Callable has bound information (Callables created with bind/unbind are unsupported).

    • Callable was created from other languages through the GDExtension API.

Some methods such as bind and unbind are not implemented, use lambdas instead:

string name = "John Doe";
Callable callable = Callable.From(() => SayHello(name));

void SayHello(string name)
{
    GD.Print($"Hello {name}");
}

The lambda captures the name variable so it can be bound to the SayHello method.

RID

This type is named Rid in C# to follow the .NET naming convention.

次のメソッドは、それぞれの名前が変更されたプロパティに変換されました:

GDScript

C#

get_id()

Id

is_valid()

IsValid

Basis(基底)

C#では、構造体にパラメーターなしのコンストラクターを含めることはできません。したがって、new Basis() はすべてのプリミティブメンバーを規定値に初期化します。 GDScriptおよびC++の Basis() に相当するものが必要な場合は ``Basis.Identity``を使用します。

次のメソッドは、異なる名前のプロパティに変換されました:

GDScript

C#

get_scale()

Scale

Transform2D

C#では、構造体にパラメーターなしのコンストラクターを含めることはできません。したがって、new Transform2D() は、すべてのプリミティブメンバーを規定値に初期化します。 GDScriptおよびC++の Transform2D() に相当するものが必要な場合は Transform2D.Identity を使用してください。

次のメソッドは、それぞれの名前が変更されたプロパティに変換されました:

GDScript

C#

get_rotation()

Rotation

get_scale()

Scale

get_skew()

Skew

Transform3D

Structs cannot have parameterless constructors in C#. Therefore, new Transform3D() initializes all primitive members to their default value. Please use Transform3D.Identity for the equivalent of Transform3D() in GDScript and C++.

次のメソッドは、それぞれの名前が変更されたプロパティに変換されました:

GDScript

C#

get_rotation()

Rotation

get_scale()

Scale

Rect2

次のフィールドは、わずかに異なる名前のプロパティに変換されました。

GDScript

C#

end

End

次のメソッドは、異なる名前のプロパティに変換されました:

GDScript

C#

get_area()

Area

Rect2i

This type is named Rect2I in C# to follow the .NET naming convention.

次のフィールドは、わずかに異なる名前のプロパティに変換されました。

GDScript

C#

end

End

次のメソッドは、異なる名前のプロパティに変換されました:

GDScript

C#

get_area()

Area

AABB

This type is named Aabb in C# to follow the .NET naming convention.

次のメソッドは、異なる名前のプロパティに変換されました:

GDScript

C#

get_volume()

Volume

Quaternion

Structs cannot have parameterless constructors in C#. Therefore, new Quaternion() initializes all primitive members to their default value. Please use Quaternion.Identity for the equivalent of Quaternion() in GDScript and C++.

Projection

Structs cannot have parameterless constructors in C#. Therefore, new Projection() initializes all primitive members to their default value. Please use Projection.Identity for the equivalent of Projection() in GDScript and C++.

Structs cannot have parameterless constructors in C#. Therefore, new Color() initializes all primitive members to their default value (which represents the transparent black color). Please use Colors.Black for the equivalent of Color() in GDScript and C++.

The global Color8 method to construct a Color from bytes is available as a static method in the Color type.

The Color constants are available in the Colors static class as readonly properties.

次のメソッドは、異なる名前のプロパティに変換されました:

GDScript

C#

get_luminance()

Luminance

The following method was converted to a method with a different name:

GDScript

C#

html(String)

FromHtml(ReadOnlySpan<char>)

The following methods are available as constructors:

GDScript

C#

hex(int)

Color(uint)

hex64(int)

Color(ulong)

配列

The equivalent of packed arrays are System.Array.

See also PackedArray in C#.

Use Godot.Collections.Array for an untyped Variant array. Godot.Collections.Array<T> is a type-safe wrapper around Godot.Collections.Array.

See also Array in C#.

辞書(ディクショナリ)

Use Godot.Collections.Dictionary for an untyped Variant dictionary. Godot.Collections.Dictionary<TKey, TValue> is a type-safe wrapper around Godot.Collections.Dictionary.

:ref:`C# のディクショナリ <doc_c_sharp_collections_dictionary>`も参照してください。

バリアント

Godot.Variant is used to represent Godot's native Variant type. Any Variant-compatible type can be converted from/to it.

See also: C# Variant.

他のスクリプト言語との通信

これは クロスランゲージでのスクリプト作成 で詳細に説明されています。

await keyword

Something similar to GDScript's await keyword can be achieved with C#'s await keyword.

The await keyword in C# can be used with any awaitable expression. It's commonly used with operands of the types Task, Task<TResult>, ValueTask, or ValueTask<TResult>.

An expression t is awaitable if one of the following holds:

  • t is of compile-time type dynamic.

  • t has an accessible instance or extension method called GetAwaiter with no parameters and no type parameters, and a return type A for which all of the following hold:

    • A implements the interface System.Runtime.CompilerServices.INotifyCompletion.

    • A has an accessible, readable instance property IsCompleted of type bool.

    • A has an accessible instance method GetResult with no parameters and no type parameters.

An equivalent of awaiting a signal in GDScript can be achieved with the await keyword and GodotObject.ToSignal.

例:

public async Task SomeFunction()
{
    await ToSignal(timer, Timer.SignalName.Timeout);
    GD.Print("After timeout");
}