Forked from mohapsat/instance scenes from array vars
Created
December 31, 2020 06:02
-
-
Save bitmammoth/7c563ce752276d816e96d1954ca34482 to your computer and use it in GitHub Desktop.
[Godot 3] instance scenes from array vars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create 2 scenes 0.tscn and 1.tscn | |
# Add a Node and call it main | |
# Add script as below to main | |
extends Node | |
var scenes = [0,1] | |
func _ready(): | |
# randomize() | |
for id in scenes: | |
var scene_path = "res://"+str(scenes[id])+".tscn" | |
# print("scene path = " + str(scene_path)) | |
var scene_pre = load(str(scene_path)) # use load instead of preload | |
var scene = scene_pre.instance() | |
add_child(scene) | |
func _process(delta): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment