#Still getting null on a variable despite defining it via @onready
1 messages · Page 1 of 1 (latest)
It needs to be defined in the scene tree as myersguy said, you're basically saying with "#ColorRect" to "get_node("ColorRect")" as being the direct children of it.
Will post the scene tree after work
I assume that’s the main menu node?
Or did I just jump into this whole thing without doing something every project needs lol
Okay so from what I am seeing, I need to create a scene tree before doing anything else in every project moving forward, is that correct?
Here we are
So what I need to do is to make transition_screen the child of the main menu node?
Also if I were to want to call on any transitions or animations I'd make throughout the game, would I need an alternate layout?
Granted, I could just define the animationplayer within the main menu scene itself
But would they animations be callable outside of the main menu scene?
So the line @onready var color_rect = $ColorRect means "On ready, set color_rect to the node ColorRect". That is to say, it is looking for a node in your scene tree named ColorRect (which doesn't exist). Add a ColorRect to your scene tree, and then control click and drag it into your script. You'll get an onready var that references that particular node.
Okay, I'll define it in the main menu gd
Otherwise, I guess I'll need to make a tscn just ofr the colorrect?
No, you just need the node to be in the scene tree with whatever node has the script attached (as a child is usually easiest) and then need a way to reference it (the control drag method is easy, but prone to breaking if you move things around on the tree)
So basically, I'd want to make the transition_scene a child of one of these other scenes? Or do I actually have to make an entirely seperate scene just fot the colorrect I want to define?
This is where the Colorrect is within the canvaslayer
so basically
the line is saying I want a child that is a ColorRect node
and transition_screen is a scene, with that script
so it looks right now.
Is that what we I have right now with this image?
Apologies if this sounds obvious, I’m new to Godot and am struggling to grasp this concept. Like I understand the scene tree and what is needed, I’m just confused on what exactly I need to do?
Do I add a line of code defining colorrect? Do I have to make a brand new scene, that is the child of transition_screen, with the colorrect node in place of what I’ve done so far? Could this be related to the way the nodes are aligned when I posted them via remite while playing my game?
Again, apologies if this is obvious and I’m just a bit of a numbskull.
Once my Autism finds the switch to this issue, it’s all going to make sense trust me lol
If you want a quick solution, just make this thing not globals, you should have enough knowledge to make it work
But if you want to upgrade your skills in godot, there is plenty article / youtube tutorials. For this problem you can start with these keywords
Godot scene tree, godot onready annotation, godot globals
I found this good tutorial, but this specific article is at module 5 https://school.gdquest.com/courses/learn_2d_gamedev_godot_4/loot_it_all/node_creation_and_ready#how-godot-creates-nodes-when-running-the-game
I'm about to scream yall
I did the control drag method
Even dragged it to the main menu tsn
let's try something: instead of doing @onready var color_rect: ColorRect = $ColorRect do:
var color_rect : ColorRect
func _ready():
color_rect = $ColorRect
# the rest of your code blablabla
@dreamy matrix
On the main menu gd yes?
on that script here
Trying now
Program seems to want @tardy magnet
lmao poor choice of nick
you wrote that wrong
var color_rect : ColorRect
not var color_rect : ColorRect = $ColorRect
the fact that this doesn't work is normal, for the reason given by the error
oops
would you mind showing the stack trace btw
Same error
please show the whole stack trace in the dock below
Like this?
hmmmmmmmmmm
why
can you show me your autoload settings as well
you arent accessing it
and that's what's being executed
is it an autoload script?
it's an autoload scene, at least if op properly set it up like they think they did
if its a script without a node then it cant get a reference to the node cause that expects the nodes to be as childre nof the actual node
for example
So I was following a tutorial that said to make that transition sceen script global
nono they're not
whats he doing then
see above
it's this
I'm trying to be able to call this transitions from anywhere in the program
please show your autoload settings
show ss of the autoload panel
So I'm making a visual novel, and want to use that fadeout transition to end chapters as well as in the main menu
ok
here you're autoloading your script
^
because that actually has the nodes as children
so you can access them as references.
im doing the same thing as you
(filesystem dock on the right? how scandalous >:o)
not really
its cause code is
from the left
i do the same on vscode
and vs
i jest you can do what you want in your life
i have my taskbar on the top of my screen
rebellion fuels the soul of men
i was gonna say, alternatively @dreamy matrix, you could choose not to bother with an autoloaded scene at all
Ok
on my projects i usually have a MainScene as my root
same...
i do have an autoload for the signalbus i call it with but that's it
np have a good one o7
good luck getting it working
signalbus
the thing with signalbus is you gotta make sure you comment exactly where the signals come from and go
otherwise eventually it becomes
veryyy
cluttered
Bad news guys, the error persisted
I wonder if it'd be easier to just keep the fade transition within the main menu node, make it global, than rely upon it until I can later figuree out how to resolve this
this looks like the error I just fixed on my game: https://discord.com/channels/1235157165589794909/1404283655060455515
From your initial post, it looks like we have similar development styles, so maybe this is the same error. (I am a software developer getting into Godot and finding out the hard way that instead of doing everything in code, some things are better done in the editor, because Godot nodes/scenes do a lot of invisible stuff I don't account for in code)
you need to remove transition_screen.gd from the autoload!
you're still running that script atm
Done
Now it has a different error
Note to self, never blindly trust turtorials again
wadda heck is transitionscreen?
did you declare it
the error tells you whats wrong
Your auto load is set as TransitionScreen not transitionacreen try making it Pascal case to match? (Disclaimer that I am big noob)
I double checked the tutorial and copied the code word for word. I figured the transitionscreen was declared come me making it global
Ugh, well I solved the original problem. Now the program claims it doesn't have access to on_transition_fninished despite the tcsn being global
The woes of coding continue
try removing first _ from func _on_animation_finished
lets see!
No dice, same error
I seriously wonder if I'm overcomplicating things.
oh i think you are looking for property on await
but its a function
so add () at the end
of await line
await transition_screen.on_transition_finished()
any ideas? Tried an @onready command and no dice
what is your canvas layer for?
screen transitions
So the idea is, I'd consult the screenlayer for stuff like fade_outs if needed
Versus keeping everything locked to the main menu node
did you actually change it to await transition_screen.on_transition_finished like anxy suggested
they told you it was a signal and not a function but then you didn't say anything about it
Yup
what was the error?
oh no wait i get it my bad
wait
@dreamy matrix your signal is named _on_transition_finished not on_transition_finished
Oh my god
I finally fixed it!
Jesus christ
I just had to delete the parenthesis
Fucking hell yall lmao
yes that be what we said
Sorry I didn’t notice it sooner, work kicked my ass
