#Still getting null on a variable despite defining it via @onready

1 messages · Page 1 of 1 (latest)

limber plover
#

Need to see the scene tree gdthumbsup

dull zealot
#

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.

dreamy matrix
#

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

dreamy matrix
#

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?

limber plover
#

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.

dreamy matrix
#

Okay, I'll define it in the main menu gd

#

Otherwise, I guess I'll need to make a tscn just ofr the colorrect?

limber plover
#

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)

dreamy matrix
#

Ok

#

Ugh, thjis is tricky

dreamy matrix
# dreamy matrix Here we are

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?

dreamy matrix
dull zealot
#

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.

dreamy matrix
# dull zealot the line is saying I want a child that is a ColorRect node

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

whole musk
#

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

dreamy matrix
#

I'm about to scream yall

#

I did the control drag method

#

Even dragged it to the main menu tsn

red echo
#

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

dreamy matrix
#

On the main menu gd yes?

red echo
dreamy matrix
#

Trying now

dreamy matrix
red echo
#

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

dreamy matrix
#

oops

red echo
#

would you mind showing the stack trace btw

dreamy matrix
#

Same error

red echo
#

please show the whole stack trace in the dock below

dreamy matrix
#

Like this?

red echo
#

hmmmmmmmmmm

dawn temple
#

why

red echo
#

can you show me your autoload settings as well

dawn temple
#

wait

#

where is that script

red echo
#

yeah i'm wondering if maybe

#

you're not autoloading the script instead of the scene

dawn temple
#

you arent accessing it

red echo
#

and that's what's being executed

dawn temple
#

is it an autoload script?

red echo
dawn temple
#

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

dreamy matrix
dawn temple
#

if you were trying to get the colorrect node in the picture.

#

like this

dawn temple
#

whats he doing then

red echo
#

see above

dreamy matrix
dawn temple
#

oh

#

yea

#

check the autoload

#

your probably autoloading the .gd

#

not the .tscn

red echo
#

please show your autoload settings

dawn temple
#

show ss of the autoload panel

dreamy matrix
#

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

dawn temple
#

idm that just show t he autoload

#

its prob that

dreamy matrix
red echo
#

yyyyep

#

that'd be incorrect

dawn temple
#

yea

#

your loading .gd

red echo
#

here you're autoloading your script

dawn temple
#

the script

#

load the transition_screen.tscn file

#

instead

red echo
#

^

dawn temple
#

because that actually has the nodes as children

#

so you can access them as references.

red echo
dawn temple
#

its cause code is

#

from the left

#

i do the same on vscode

#

and vs

red echo
#

i jest you can do what you want in your life

dawn temple
#

fr

#

🥹

red echo
#

i have my taskbar on the top of my screen

dawn temple
#

😮

red echo
#

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

dreamy matrix
#

Ok

red echo
#

on my projects i usually have a MainScene as my root

dawn temple
red echo
#

which is the scene manager in itself

#

and all my scenes are children of that

dreamy matrix
#

Hey guys I gotta go to work I will try this when I get home

#

Tysm

red echo
#

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

dawn temple
#

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

red echo
#

true

#

can also have multiple though

dawn temple
#

i ususally dont prefer having too many autoloads

#

but some things are nice

#

with it

dreamy matrix
#

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

hot linden
# dreamy matrix Bad news guys, the error persisted

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)

red echo
#

you're still running that script atm

dreamy matrix
#

Done

#

Now it has a different error

#

Note to self, never blindly trust turtorials again

red echo
#

did you declare it

wispy raven
last anvil
dreamy matrix
dreamy matrix
#

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

wispy raven
#

try removing first _ from func _on_animation_finished

dreamy matrix
#

lets see!

#

No dice, same error

#

I seriously wonder if I'm overcomplicating things.

wispy raven
#

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()

dreamy matrix
#

hnnn

#

Nope...

wispy raven
#

oh its not a function

#

its a signal on_transition_finished

#

my bad

#

messed it up

dreamy matrix
#

any ideas? Tried an @onready command and no dice

wispy raven
#

what is your canvas layer for?

dreamy matrix
#

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

red echo
#

they told you it was a signal and not a function but then you didn't say anything about it

red echo
#

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

dreamy matrix
#

I’ll check it after work

#

Thank yoy for continuing to respond so late

dreamy matrix
#

Oh my god

#

I finally fixed it!

#

Jesus christ

#

I just had to delete the parenthesis

#

Fucking hell yall lmao

red echo
dreamy matrix
#

Sorry I didn’t notice it sooner, work kicked my ass