I am kinda using this post as place to record my journey of troubleshooting, just in case. Please let me know if I am not suppose to do this.
Troubleshooting Update:
I tried the following (suggested by @vonpanda) to see the different between the node.get_parent()
and the Globals
variables.
if Input.is_action_just_pressed("ui_accept"):
var interaction = interaction_check.get_overlapping_areas()
if interaction.size() > 0:
interaction[0]._interaction()
print("interaction:")
var temp = interaction[0].get_parent()
print(temp)
temp.print_tree_pretty()
print("global:")
var temp_g = Block
print(temp_g)
temp_g.print_tree_pretty()
And it is found out that, the Globals
actually return the Node
object and the node.get_parent()
return the RigidBody3D
object.
interaction:
Block:<RigidBody3D#37228643666>
ââ´Block
â â´MeshInstance3D
â â´CollisionShape3D
ââ´InteractionLayer
ââ´CollisionShape3D
global:
Block:<Node#33957086478>
ââ´Block
It could be as my Block
is actually an instance created from another scene. So I proceed to break it down and create a complete Block
node.
Running the same code give me the following.
interaction:
RigidBody3D:<RigidBody3D#28756149520>
ââ´RigidBody3D
â â´Area3D
â ââ´CollisionShape3D
â â´MeshInstance3D
ââ´CollisionShape3D
global:
RigidBody3d_obj:<RigidBody3D#28051506444>
ââ´RigidBody3d_obj
Which now return the Globals
one as RigidBody3D
, but still not the same object.
Findings:
So apparently, the node.get_parent()
will not able to return the variables that are registered as Globals
, since the Globals
didnât recognize (or I should say didnât have) the child nodes. And I only then realize my question is actually something else from the Area3D.get_overlapping_areas().get_parent()
, but it could be Globals
related.
Went on to research that part, and in here [Singletons (Autoload) â Godot Engine (4.3) documentation in English] it says:
Godotâs scene system, while powerful and flexible, has a drawback: there is no method for storing information (e.g. a playerâs score or inventory) that is needed by more than one scene.
Which seems to be related to my case. Apparently, Globals
or the Singletons
feature is actually created as the other method (node.get_parent()
, get_node()
, or $...
are not able to be a place to store value.
Make sense now, so gonna tweak a bit on my approach.