Is it possible to instantiate a scene in the 3D editor without making it a part of the scene I’m editing?
I’m working on a physics-based pinball simulator and my development process involves creating simple placeholder objects in the engine to allow me to implement their behavior and tweak their properties before bothering with modeling them accurately in CAD or Blender. It would be a big help to be able to instantiate a scene in the 3D editor without making it a part of the scene hierarchy to use as a reference for the general scale of objects. In the case of my pinball project I want to have the scene which represents the ball to be present in every other scene so that I can compare the objects I’m implementing with it as a rough guide.
Currently I can do that by dragging the ball scene into the active scene, but I don’t want it to be instantiated when I drag the object into my scene which combines to objects to create the pinball playfield, so I have to delete it from the scene when I’m done. This is annoying while I’m iterating on the scene as I may have to re-add the ball to the scene and re-remove it when I’m done tweaking several times over.
I would like to be able to define a scene to be part of the “default scene” which is displayed in any 3D editor instance no matter what scene I’m currently editing. Is there a way to do this in the engine currently as a built-in setting? If not, is there an extension which implements this behavior? If neither are the case does anyone have ideas as to where I could start to implement this as my own Godot extension?
For reference, here is an object that I’m working on, and I’ve added the ball to the scene to have a scale comparison. I still want to be able to move the ball around with the transform gizmos, but I don’t want this to be part of the scene when it’s instantiated elsewhere.
I would make a Tool class named BackgroundScene, that checks if the tool is running on the Editor. And only if it does the script would instatiate the scene.
You will be able to see the background scene, only while editing.
The script could have parameters so you can set the scene to instantiate, and toggle it on and off.
Did a quick search on the AssetLib and didn’t see anything like this, could be a cool contribution.
I’m not sure if I understood your problem correctly…
But if you want to have a scene instantiated automatically in every new scene that sounds like a job for a plugin for me.
I loved figuring this one out as I have no idea what I’m doing when writing @tool scripts.
The non-editor plugin version looks like this. Just chuck it as a child node of the root scene, add a reference scene. From what I tested it seems to work, but try in an exported game as well.
@tool
## Adds a reference scene to the Editor 3d view if the parent scene is the scene root
class_name ReferenceScene
extends Node
@export var reference_scene : PackedScene:
set(value):
reference_scene = value
update_configuration_warnings()
_apply_scene()
@onready var target_node : Node = get_parent()
var _instantiated_scene : Node = null
func _ready() -> void:
_apply_scene()
func _apply_scene() -> void:
if not Engine.is_editor_hint():
return
if not reference_scene:
remove_instantiated_scene()
return
var target_is_root := target_node == get_tree().edited_scene_root
if target_is_root:
remove_instantiated_scene()
_instantiated_scene = reference_scene.instantiate() # PackedScene.GEN_EDIT_STATE_INSTANCE)
add_child(_instantiated_scene)
# this prevents visual, save, edit, I hope
_instantiated_scene.owner = self
func remove_instantiated_scene() -> void:
if _instantiated_scene:
_instantiated_scene.queue_free() # docs say this is dangerous
_instantiated_scene = null
func _get_configuration_warnings() -> PackedStringArray:
var warnings := PackedStringArray()
if reference_scene == null:
warnings.append("Missing reference scene")
return warnings