system
1
|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
hnuqweasd |
|
Old Version |
Published before Godot 3 was released. |
E.g. in GDscript you can do:
var scene = preload(“res://myscene.scn”)
var node = scene.instance()
add_child(node)
How do you do the equivalent in C#?
system
4
|
|
|
|
Reply From: |
hnuqweasd |
Not sure if this is the way to do it but after reading Introducing C# in Godot again I did:
PackedScene ground;
public override void _Ready()
{
ground = (PackedScene)ResourceLoader.Load("res://scenes/Ground.tscn");
StaticBody2D newGround = (StaticBody2D)ground.Instance();
AddChild(newGround);
}
Yup, that’s it
Zylann | 2017-11-03 01:10
system
5
|
|
|
|
Reply From: |
steelx |
my answer is not detailed, but
you can initial MyScene.cs
with _Notification
so that it can be preloaded in another Csharp file just as a variable.
public class AnotherScene : Node2D
{
public PackedScene Rooms = ResourceLoader.Load<PackedScene>("res://myscene.tscn");
}