|Topic was automatically imported from the old Question2Answer platform.
How can we make a node globally acessable to other nodes in stabilished trees?
Say I have a camera inside my player node, and I have a fog texture in a canvas node, which it’s shader will use the camera position to offset the UV. How do I make the camera globally acessable? I am familiar with autoloads, but I can’t get it to work properly, my intention is to make a standard structure of nodes for my game maps, like:
Then some objects could store their reference in a global node, then they could be called from any other node in the map. My current situation is the FOG texture shader trying to access the camera inside the player. I would do currently a lot of
My project is getting bigger, and so far have been doing direct referencing like
get_node() or $ pathing, which I know, isn’t the best approach, my
get_parent() get_tree() get_node() codes are looking like a noodle soup, no pun intended, it’s all over the place.
Sometimes I can bypass this using the dinamic design approach, wherer B doesn’t need to know A to do X. I do this using classes and pre-determined common variables like OBJECT_TYPE:Door, or using the collision layers, or using other methods like filtering by NODE type, but sometimes we need to reference a specific object like the Player.
So how can I store the path of a node or the node itself in a global access point? Or my approach with this situation is wrong?