wokesmeed easy, connect the desired signal on your enemy when it is instanced to the player (or node that is handling stats) and then tie your "leveling up" logic to that signal. You could even make a custom signal on the enemy that, say, when it is killed, transfers a value to the player to "level up" (though full honesty, you may want to use a global set of variables for stats, as they won't transfer from scene to scene without some sort of "container.") That "level up" or "xp" function could be something you plug into an Area2D signal (like say, when a weapon hits an enemy). Note: This logic in this example is faulty. You don't want to connect this to tree_exiting
normally because then you'd trigger your level up/xp function every time you change scenes (because the enemies leave with it).
But if you wanted to connect the signal with a "handler" node, you could just drop a Node2d in the scene and seek out your objects. The other easy option is to simply hide your enemy nodes until you need them and simple hide them and connect your xp function to when they "disappear."
This is a broad example, hard to consider implementation without code in front of me. But the example should teach how to connect signals in code at an instancing.
var _parentScene = get_parent() ## get parent scene
var _enemy ## empty container for enemy
export var _enemySource : String ## export so you can paste enemy filepath for instance into inspector
onready var _player = $Player ## find player in scene
func _on_enemy_Spawn():
var _newEnemy = _enemySource.instance() ## we instance the enemy
_parentScene.add_child(_newEnemy) ## add it to parent scene so it can move on its own
_enemy = _newEnemy ## fill our enemy container with our newly instanced target
_enemy.connect("tree_exiting", _player, "_enemy_xp_acquire") ## and connect.
'_enemy.connect()' is the function, with _enemy being your connecting object and in the parantheses, three ## arguments
- the signal you want to connect
the target to connect to
and the function to trigger in the target - in that exact order.
Then you could make a function in the player for "_enemy_xp_acquire" and put your logic there. You may want to play with different signals and functions to get it right. Good luck!