3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Godot Engine - 実行時にノードをシーンとして保存する

Last updated at Posted at 2020-11-27

環境

  • Windows10 home
  • Godot Engine v3.2.3.stable.mono.official

手順

  1. 親ノードに以下スクリプトをアタッチ
  2. 実行
  3. デバッグダイアログを閉じる
  4. シーンが保存される

使い道

  • 自動生成ダンジョンなどの保存
  • インポートした素材などの保存

スクリプト

(: 子ノードを保存する)
extends Node

func _ready() -> void:
    var child = get_child(0)
    var path = "res://sample/" + child.name + ".tscn" # 指定ディレクトリが存在しなければエラー
    var ps = PackedScene.new()
    ps.pack(child)
    ResourceSaver.save(path, ps)


(2: 最下層の子ノードを全て保存する)
extends Node

func _ready() -> void:
    for i in range(get_child_count()):
        var child = get_child(i)
        SaveNode(child)

func SaveNode(child: Node) -> void:
    var count = child.get_child_count()
    if (count > 0):
        for i in range(count):
            SaveNode(child.get_child(i))
    else:
        var path = "res://sample/" + child.name + ".tscn"
        var ps = PackedScene.new()
        ps.pack(child)
        ResourceSaver.save(path, ps)

参考

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?