Table of Contents

Class Script

Namespace
Godot
Assembly
GodotSharp.dll

A class stored as a resource. A script extends the functionality of all objects that instantiate it.

This is the base class for all scripts and should not be used directly. Trying to create a new script with this class will result in an error.

The new method of a script subclass creates a new instance. SetScript(Variant) extends an existing object, if that object's class matches one of the script's base classes.

public class Script : Resource, IDisposable
Inheritance
Script
Implements
Derived
Inherited Members

Properties

SourceCode

The script source code or an empty string if source code is not available. When set, does not reload the class implementation automatically.

public string SourceCode { get; set; }

Property Value

string

Methods

CanInstantiate()

Returns true if the script can be instantiated.

public bool CanInstantiate()

Returns

bool

GetBaseScript()

Returns the script directly inherited by this script.

public Script GetBaseScript()

Returns

Script

GetInstanceBaseType()

Returns the script's base type.

public StringName GetInstanceBaseType()

Returns

StringName

GetPropertyDefaultValue(StringName)

Returns the default value of the specified property.

public Variant GetPropertyDefaultValue(StringName property)

Parameters

property StringName

Returns

Variant

GetScriptConstantMap()

Returns a dictionary containing constant names and their values.

public Dictionary GetScriptConstantMap()

Returns

Dictionary

GetScriptMethodList()

Returns the list of methods in this Script.

public Array<Dictionary> GetScriptMethodList()

Returns

Array<Dictionary>

GetScriptPropertyList()

Returns the list of properties in this Script.

public Array<Dictionary> GetScriptPropertyList()

Returns

Array<Dictionary>

GetScriptSignalList()

Returns the list of user signals defined in this Script.

public Array<Dictionary> GetScriptSignalList()

Returns

Array<Dictionary>

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

HasScriptSignal(StringName)

Returns true if the script, or a base class, defines a signal with the given name.

public bool HasScriptSignal(StringName signalName)

Parameters

signalName StringName

Returns

bool

HasSourceCode()

Returns true if the script contains non-empty source code.

public bool HasSourceCode()

Returns

bool

InstanceHas(GodotObject)

Returns true if baseObject is an instance of this script.

public bool InstanceHas(GodotObject baseObject)

Parameters

baseObject GodotObject

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

IsAbstract()

Returns true if the script is an abstract script. An abstract script does not have a constructor and cannot be instantiated.

public bool IsAbstract()

Returns

bool

IsTool()

Returns true if the script is a tool script. A tool script can run in the editor.

public bool IsTool()

Returns

bool

Reload(bool)

Reloads the script's class implementation. Returns an error code.

public Error Reload(bool keepState = false)

Parameters

keepState bool

Returns

Error