45 lines
1.1 KiB
GDScript
45 lines
1.1 KiB
GDScript
@tool
|
|
extends EditorScript
|
|
|
|
# Path to your new NPC scene
|
|
const NEW_NPC_SCENE := preload("res://scenes/character_seat_talking.tscn")
|
|
|
|
func _run():
|
|
var root := get_scene()
|
|
if root == null:
|
|
push_error("Open the scene in the editor before running this script.")
|
|
return
|
|
|
|
var seating := root.find_child("characters-seating", true, false)
|
|
if seating == null:
|
|
push_error("Could not find 'characters-seating' node.")
|
|
return
|
|
|
|
var replaced := 0
|
|
|
|
for grp in seating.get_children():
|
|
# Snapshot the children first, since we'll be modifying the group as we go
|
|
var old_npcs := grp.get_children()
|
|
|
|
for old_npc in old_npcs:
|
|
if not (old_npc is Node3D):
|
|
push_warning(old_npc.name + " in " + grp.name + " is not a Node3D, skipping.")
|
|
continue
|
|
|
|
var old_transform: Transform3D = old_npc.transform
|
|
var old_name := old_npc.name
|
|
|
|
var new_npc: Node3D = NEW_NPC_SCENE.instantiate()
|
|
|
|
grp.remove_child(old_npc)
|
|
old_npc.queue_free()
|
|
|
|
grp.add_child(new_npc)
|
|
new_npc.owner = root
|
|
new_npc.transform = old_transform
|
|
new_npc.name = old_name
|
|
|
|
replaced += 1
|
|
|
|
print("Replaced ", replaced, " NPC(s).")
|