Merge pull request #6437 from Calinou/update-instantiate

Update all instances of `instance()` to `instantiate()`
This commit is contained in:
Rémi Verschelde
2022-11-30 16:53:27 +01:00
committed by GitHub
15 changed files with 35 additions and 35 deletions

View File

@@ -88,7 +88,7 @@ Therefore, playback state must be self-contained in AudioStreamPlayback.
Ref<AudioStreamPlayback> AudioStreamMyTone::instance_playback() {
Ref<AudioStreamPlaybackMyTone> talking_tree;
talking_tree.instance();
talking_tree.instantiate();
talking_tree->base = Ref<AudioStreamMyTone>(this);
return talking_tree;
}

View File

@@ -337,10 +337,10 @@ when ``load`` is called.
void register_json_types() {
ClassDB::register_class<JsonResource>();
json_loader.instance();
json_loader.instantiate();
ResourceLoader::add_resource_format_loader(json_loader);
json_saver.instance();
json_saver.instantiate();
ResourceSaver::add_resource_format_saver(json_saver);
}

View File

@@ -236,7 +236,7 @@ Let's code the mob spawning logic. We're going to:
func _on_MobTimer_timeout():
# Create a new instance of the Mob scene.
var mob = mob_scene.instance()
var mob = mob_scene.instantiate()
# Choose a random location on the SpawnPath.
# We store the reference to the SpawnLocation node.
@@ -255,7 +255,7 @@ Let's code the mob spawning logic. We're going to:
public void OnMobTimerTimeout()
{
// Create a new instance of the Mob scene.
Mob mob = (Mob)MobScene.Instance();
Mob mob = (Mob)MobScene.Instantiate();
// Choose a random location on the SpawnPath.
// We store the reference to the SpawnLocation node.
@@ -288,7 +288,7 @@ Here is the complete ``Main.gd`` script so far, for reference.
func _on_MobTimer_timeout():
var mob = mob_scene.instance()
var mob = mob_scene.instantiate()
var mob_spawn_location = get_node("SpawnPath/SpawnLocation")
mob_spawn_location.unit_offset = randf()
@@ -313,7 +313,7 @@ Here is the complete ``Main.gd`` script so far, for reference.
public void OnMobTimerTimeout()
{
Mob mob = (Mob)MobScene.Instance();
Mob mob = (Mob)MobScene.Instantiate();
var mobSpawnLocation = GetNode<PathFollow>("SpawnPath/SpawnLocation");
mobSpawnLocation.UnitOffset = GD.Randf();

View File

@@ -166,7 +166,7 @@ Starting with ``Main.gd``.
func _on_MobTimer_timeout():
# Create a new instance of the Mob scene.
var mob = mob_scene.instance()
var mob = mob_scene.instantiate()
# Choose a random location on the SpawnPath.
var mob_spawn_location = get_node("SpawnPath/SpawnLocation")
@@ -201,7 +201,7 @@ Starting with ``Main.gd``.
public void OnMobTimerTimeout()
{
// Create a new instance of the Mob scene.
var mob = (Mob)MobScene.Instance();
var mob = (Mob)MobScene.Instantiate();
// Choose a random location on the SpawnPath.
// We store the reference to the SpawnLocation node.

View File

@@ -388,7 +388,7 @@ Here is the complete ``Main.gd`` script for reference.
func _on_MobTimer_timeout():
var mob = mob_scene.instance()
var mob = mob_scene.instantiate()
var mob_spawn_location = get_node("SpawnPath/SpawnLocation")
mob_spawn_location.unit_offset = randf()
@@ -429,7 +429,7 @@ Here is the complete ``Main.gd`` script for reference.
public void OnMobTimerTimeout()
{
Mob mob = (Mob)MobScene.Instance();
Mob mob = (Mob)MobScene.Instantiate();
var mobSpawnLocation = GetNode<PathFollow>("SpawnPath/SpawnLocation");
mobSpawnLocation.UnitOffset = GD.Randf();

View File

@@ -30,8 +30,8 @@ a change in API:
const MyScene = preload("my_scene.tscn")
var node = Node.new()
var my_node = MyNode.new() # Same method call
var my_scene = MyScene.instance() # Different method call
var my_inherited_scene = MyScene.instance(PackedScene.GEN_EDIT_STATE_MAIN) # Create scene inheriting from MyScene
var my_scene = MyScene.instantiate() # Different method call
var my_inherited_scene = MyScene.instantiate(PackedScene.GEN_EDIT_STATE_MAIN) # Create scene inheriting from MyScene
.. code-tab:: csharp
@@ -51,8 +51,8 @@ a change in API:
{
ANode = new Node();
MyNode = new MyNode(); // Same syntax
MyScene = MySceneScn.Instance(); // Different. Instantiated from a PackedScene
MyInheritedScene = MySceneScn.Instance(PackedScene.GenEditState.Main); // Create scene inheriting from MyScene
MyScene = MySceneScn.Instantiate(); // Different. Instantiated from a PackedScene
MyInheritedScene = MySceneScn.Instantiate(PackedScene.GenEditState.Main); // Create scene inheriting from MyScene
}
}
@@ -217,4 +217,4 @@ In the end, the best approach is to consider the following:
# main.gd
extends Node
func _ready():
add_child(Game.MyScene.instance())
add_child(Game.MyScene.instantiate())

View File

@@ -192,7 +192,7 @@ loader.
func set_new_scene(scene_resource):
current_scene = scene_resource.instance()
current_scene = scene_resource.instantiate()
get_node("/root").add_child(current_scene)
Using multiple threads
@@ -285,7 +285,7 @@ Example:
start_cutscene()
# Later, when the user presses the pause button for the first time:
pause_menu = queue.get_resource("res://pause_menu.tres").instance()
pause_menu = queue.get_resource("res://pause_menu.tres").instantiate()
pause_menu.show()
# When you need a new scene:

View File

@@ -241,7 +241,7 @@ load function:
var node_data = json.get_data()
# Firstly, we need to create the object and add it to the tree and set its position.
var new_object = load(node_data["filename"]).instance()
var new_object = load(node_data["filename"]).instantiate()
get_node(node_data["parent"]).add_child(new_object)
new_object.position = Vector2(node_data["pos_x"], node_data["pos_y"])
@@ -282,7 +282,7 @@ load function:
// Firstly, we need to create the object and add it to the tree and set its position.
var newObjectScene = (PackedScene)ResourceLoader.Load(nodeData["Filename"].ToString());
var newObject = (Node)newObjectScene.Instance();
var newObject = (Node)newObjectScene.Instantiate();
GetNode(nodeData["Parent"].ToString()).AddChild(newObject);
newObject.Set("Position", new Vector2((float)nodeData["PosX"], (float)nodeData["PosY"]));

View File

@@ -309,18 +309,18 @@ every peer and RPC will work great! Here is an example:
var selfPeerID = get_tree().get_network_unique_id()
# Load world
var world = load(which_level).instance()
var world = load(which_level).instantiate()
get_node("/root").add_child(world)
# Load my player
var my_player = preload("res://player.tscn").instance()
var my_player = preload("res://player.tscn").instantiate()
my_player.set_name(str(selfPeerID))
my_player.set_network_master(selfPeerID) # Will be explained later
get_node("/root/world/players").add_child(my_player)
# Load other players
for p in player_info:
var player = preload("res://player.tscn").instance()
var player = preload("res://player.tscn").instantiate()
player.set_name(str(p))
player.set_network_master(p) # Will be explained later
get_node("/root/world/players").add_child(player)
@@ -392,14 +392,14 @@ If you have paid attention to the previous example, it's possible you noticed th
[...]
# Load my player
var my_player = preload("res://player.tscn").instance()
var my_player = preload("res://player.tscn").instantiate()
my_player.set_name(str(selfPeerID))
my_player.set_network_master(selfPeerID) # The player belongs to this peer; it has the authority.
get_node("/root/world/players").add_child(my_player)
# Load other players
for p in player_info:
var player = preload("res://player.tscn").instance()
var player = preload("res://player.tscn").instantiate()
player.set_name(str(p))
player.set_network_master(p) # Each other connected peer has authority over their own player.
get_node("/root/world/players").add_child(player)

View File

@@ -35,7 +35,7 @@ However, creating scene chunks (nodes in tree arrangement) outside the active tr
::
var enemy_scene = load("res://enemy_scene.scn")
var enemy = enemy_scene.instance()
var enemy = enemy_scene.instantiate()
enemy.add_child(weapon) # Set a weapon.
world.call_deferred("add_child", enemy)

View File

@@ -343,7 +343,7 @@ uses the mouse pointer. Here is the code for the Player, using ``move_and_slide(
func shoot():
# "Muzzle" is a Marker2D placed at the barrel of the gun.
var b = Bullet.instance()
var b = Bullet.instantiate()
b.start($Muzzle.global_position, rotation)
get_parent().add_child(b)
@@ -387,7 +387,7 @@ uses the mouse pointer. Here is the code for the Player, using ``move_and_slide(
public void Shoot()
{
// "Muzzle" is a Marker2D placed at the barrel of the gun
var b = (Bullet)_bullet.Instance();
var b = (Bullet)_bullet.Instantiate();
b.Start(GetNode<Node2D>("Muzzle").GlobalPosition, Rotation);
GetParent().AddChild(b);
}

View File

@@ -12,7 +12,7 @@ scenes which one instances and adds to the tree at runtime:
.. tabs::
.. code-tab:: gdscript GDScript
var simultaneous_scene = preload("res://levels/level2.tscn").instance()
var simultaneous_scene = preload("res://levels/level2.tscn").instantiate()
func _add_a_scene_manually():
# This is like autoloading the scene, only
@@ -25,7 +25,7 @@ scenes which one instances and adds to the tree at runtime:
public MyClass()
{
simultaneousScene = ResourceLoader.Load<PackedScene>("res://levels/level2.tscn").Instance();
simultaneousScene = ResourceLoader.Load<PackedScene>("res://levels/level2.tscn").Instantiate();
}
public void _AddASceneManually()

View File

@@ -68,7 +68,7 @@ You could do this by adding the bullet to the main scene directly:
.. code-tab:: csharp
Node bulletInstance = Bullet.Instance();
Node bulletInstance = Bullet.Instantiate();
GetParent().AddChild(bulletInstance);
However, this will lead to a different problem. Now if you try to test your
@@ -145,7 +145,7 @@ In the main scene, we then connect the player's signal (it will appear in the
public void _on_Player_Shoot(PackedScene bullet, Vector2 direction, Vector2 location)
{
var bulletInstance = (Bullet)bullet.Instance();
var bulletInstance = (Bullet)bullet.Instantiate();
AddChild(bulletInstance);
bulletInstance.Rotation = direction;
bulletInstance.Position = location;

View File

@@ -132,7 +132,7 @@ To get an instance of the scene, you have to use the
public void OnShoot()
{
Node bullet = _bulletScene.Instance();
Node bullet = _bulletScene.Instantiate();
AddChild(bullet);
}

View File

@@ -203,7 +203,7 @@ current scene and replace it with the requested one.
var s = ResourceLoader.load(path)
# Instance the new scene.
current_scene = s.instance()
current_scene = s.instantiate()
# Add it to the active scene, as child of root.
get_tree().root.add_child(current_scene)
@@ -236,7 +236,7 @@ current scene and replace it with the requested one.
var nextScene = (PackedScene)GD.Load(path);
// Instance the new scene.
CurrentScene = nextScene.Instance();
CurrentScene = nextScene.Instantiate();
// Add it to the active scene, as child of root.
GetTree().Root.AddChild(CurrentScene);