I'm posting this question about a problem that I encounter currently in my project.
About the problem itself :
- I have set a "character" as an Area (3D), and that is monitoring.
- I have set some objects as Area (3D) too, that are monitorable.
- I've made a connect("area_enter",self,"someFunc") on the character node.
And, at the first time, it works PERFECTLY FINE ! someFunc() is called everytime when my character enter an Object.
The problem occurs when I leave the scene and load another, and then come back to the scene. After some times, many objects aren't detected anymore. It seems that my "area-enter" signal is not emitted anymore.
So, have you any idea about why it doesn't work ? Why it bugs when i'm leaving the scene and then comes back ?
In order to "show" my problem in details:
This is my script for the character:
var SPEED_FORWARD = Global.SPEED
const SPEED_SIDE = 450
const SPRITE_SIZE = 50
const SIZE_MAP = 720
inputNode = get_node("../ControlCharacterUI/CharacterUI")
self.connect("area_enter", self, "on_area_enter")
#We get the move wanted by the user by calling the appropriate node.
side = inputNode._get_move()
#If the right or left limit of the "moving zone" is reached, we forbid the move.
if(self.get_transform().origin.x - SPRITE_SIZE < -SIZE_MAP/2):
if (side == -1):
side = 0
if(self.get_transform().origin.x + SPRITE_SIZE > SIZE_MAP/2):
if(side == 1):
side = 0
# We move the character forward and left/right according to the side previously get
self.translate(Vector3(side * SPEED_SIDE * delta, 0, -delta * SPEED_FORWARD))
func on_area_enter( area ):
And there my script for the objects:
var isAlreadyCollided = false
isAlreadyCollided = true
-----DOING SOME IRREVELANT HERE-----
Here are screens :
(Objects have the same parameters, except for being monitorable instead of monitoring, and the shape, that is a BoxShape instead of a CapsuleShape)
For the context :
The elements/objects are dispatched in a "Level1.tscn":
And next, in a main scene, there is our Character, and a script add the "Level" as a child of an "AllElements" node.
And here the portion of script used in AllElements:
var scene = load("res://Levels/Level1.tscn")
var instance = scene.instance()
Final scene : http://img15.hostingpics.net/pics/348996Final.png
SO, that's all for how it is done.
The problem occurs when we switch between the main scene and another scene, and then come back to the main scene. It's done with :
in the "main.tscn" and
in the "MainMenu.tscn".
Where Global.goto_scene(path) is :
var current_scene = null
var s = ResourceLoader.load(path)
current_scene = s.instance()
get_tree().set_current_scene( current_scene )
After changing of scene ( main.tscn -> MainMenu.tscn -> main.tscn ... ) like 2 to 4 times, the area-enter signal doesn't work anymore.
Have you any idea ? Thanks you in advance !
EDIT: The same problem occurs if, for example, I load the Level1.tscn on ready() 's function of AllElements, then instanciate it, then queue_free() it, then re-instanciate it. After a while, some elements aren't detected by area_enter anymore.