Just add gravity

Godot Version

v4.3.stable.official [77dcf97d8]

Question

I created an editor plugin that opens a 3D scene in a separate Window. The scene displays and functions normally except there is no gravity. Gravity works fine if I open the same scene by running the project.

I’m guessing that opening the scene as part of the editor plugin does not establish a proper environment. What am I missing?

I think your problem is similar to this

I have @tool in all the involved scripts. Everything works as expected, including move_and_slide(), Only get_gravity() always returns Vector3.ZERO.

I solved the problem by checking for zero gravity and forcing a hardcoded gravity.

In _physics_process():

func _physics_process(delta: float) -> void:
	var gforce:Vector3;
	
	if get_gravity() == Vector3.ZERO:
		gforce = Vector3(0.0, -9.8, 0.0);
	else:
		gforce = get_gravity();

1 Like

You could try explicitly setting the gravity in your plugin’s initialization code. Make sure that the physics engine is properly set up when you load the scene in the separate window.