Help with scene transitions and area3D

Godot Version

4.2.2

Question

I’ve been writing a script that if it was working would cause the player to change scenes when entering an area3D, however despite no errors popping up-nothing is happening. Any help would be appreciated. (Code bellow)

extends Area3D


# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.

func _on_Area_body_entered(_body):
	get_tree().change_scene("res://InteriorLightHouse.tscn")

.

There not being an error message indicates to me that the function isn’t being called. You can test that by adding print("Hello") inside of the function. If you test it and see a Hello pop up in the Output tab, then you know it is being called.

If there is no Hello then check if your signals are connected corretly. You can tell by there being a green arrow and door icon next to the function in the script editor. You can even click it to see who is emitting the signal and calling the function. If there isn’t an icon then you need to reconnect the signal from the emitting node.

Also, I believe you have to change your code to get_tree().change_scene_to_file("res://InteriorLightHouse.tscn") as you are trying to switch to a scene that is being called by file name. I don’t think you can do it without the to_file.

Hope that helps. :>

You were right, the script isn’t being triggered, I updated the script’s syntax as you recommended, do you have any Idea why the script might not be triggering?
Right now I have an area3D and a collisionShape3D trying to detect the player (Which is a characterbody3D and a area3D with collision shapes)

Could be a number of things. First I would check if the collision layers and masks are set up correctly. In order for the area to detect when the player entered, the area’s mask must include the layer of the player. So if the CharacterBody3D of the player is set on layer 1, then the mask of the Area3D of your door (I assume it’s a door) must also include 1. See below:

However, if you haven’t messed with these values in the first place, then this should not be causing any issues. Another thing to remember is that the body_entered() signal will only trigger when a body is entering the area. You also mentioned your player contains an Area3D. This signal will not trigger when your player’s area is entering the other area. For that, use the area_entered() signal. Just mentioning it because that can cause confusion.

So yeah, make sure the CollisionShape of your CharacterBody3D is actually entering the area. Not just the CollisionShape of your players Area3D.

Oh, and I also just remembered that Monitoring has to be set to true on the Area3D that is supposed to emit the signal. Make sure that is the case as well.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.