![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Burloe |
I know this has been asked and answered many times before but i must’ve missed or misunderstood something cause nothing in those questions seems to work for me.
I’m making a sort of debugging overlay for myself to display some variables in-game while I’m working on a weather system and I prefer to have my debugging code centralized in one script if possible(UserInterface.gd in this case).
I have my village map/scene with a Player.tscn with the UI.gd in it and a CanvasModulate for changing the tint of the scene depending on the weather. This CanvasMod has a script attached called WeatherManager,gd with the variable I want to access and display on my UI called “currentWeather”(contains a string with the current weather).
So in the UI.gd, this is the basic code I’ve tried but it always return null which indicates an incorrect path:
onready var canvasMod = get_node("/Village/CanvasModulate")
func _physics_process(delta):
var _curW = canvasMod.currentWeather
if $CurrentWeathr:
$CurrentWeathr.text = str("Weather - ") + str(_curW)
I’ve also tried using $CanvasModulate and every possible path I can think of :
/…/CanvasModulate
/CanvasModulate
/root/Village/CanvasModulate
/root/CanvasModulate
Also tried the filepath:
res://Game Scenes/Village.tscn
This solution too which I found in another question:
get_node(“object here”).variable
etc
SceneTree looks like this:
- Village
-----TileMap(of course a bunch of other TM’s and other things but unrelated to the question)
-----YSort
----- -----Player - Inside it’s separately saved scene:
----- ----- -----UserInterface(CanvasLayer type with UserInterface.gd attached)
----- ----- -----CurrentWeathr(Label type)
-----CanvasMod(WeatherManager.gd attached
Any and all help is appreciated. Sorry for the long post. Thanks!
try
var villa = load("res://GameScenes/Village.gd").new()
or
player script
var villa
func _ready():
villa = get_owner().get_node("CanvasMod")
pass
func example():
villa.func_name_in_the_canvasmod()
pass
ramazan | 2022-09-18 12:24