.. _doc_godot_interfaces: Godot interfaces ================ Often one needs scripts that rely on other objects for features. There are 2 parts to this process: 1. Acquiring a reference to the object that presumably has the features. 2. Accessing the data or logic from the object. The rest of this tutorial outlines the various ways of doing all this. Acquiring object references --------------------------- For all :ref:`Object `\s, the most basic way of referencing them is to get a reference to an existing object from another acquired instance. .. tabs:: .. code-tab:: gdscript GDScript var obj = node.object # Property access. var obj = node.get_object() # Method access. .. code-tab:: csharp Object obj = node.Object; // Property access. Object obj = node.GetObject(); // Method access. The same principle applies for :ref:`Reference ` objects. While users often access :ref:`Node ` and :ref:`Resource ` this way, alternative measures are available. Instead of property or method access, one can get Resources by load access. .. tabs:: .. code-tab:: gdscript GDScript var preres = preload(path) # Load resource during scene load var res = load(path) # Load resource when program reaches statement # Note that users load scenes and scripts, by convention, with PascalCase # names (like typenames), often into constants. const MyScene : = preload("my_scene.tscn") as PackedScene # Static load const MyScript : = preload("my_script.gd") as Script # This type's value varies, i.e. it is a variable, so it uses snake_case. export(Script) var script_type: Script # If need an "export const var" (which doesn't exist), use a conditional # setter for a tool script that checks if it's executing in the editor. tool # Must place at top of file. # Must configure from the editor, defaults to null. export(Script) var const_script setget set_const_script func set_const_script(value): if Engine.is_editor_hint(): const_script = value # Warn users if the value hasn't been set. func _get_configuration_warning(): if not const_script: return "Must initialize property 'const_script'." return "" .. code-tab:: csharp // Tool script added for the sake of the "const [Export]" example. [Tool] public MyType { // Property initializations load during Script instancing, i.e. .new(). // No "preload" loads during scene load exists in C#. // Initialize with a value. Editable at runtime. public Script MyScript = GD.Load