How to check if variable is default or changed

Godot Version

4.2

Question

Hey, I got this variable that never is really null. I ran problems with setting it as null but now it is harder to check if it is default value or not:

var item = Resource

so thats the variable, and in code I can put a item.tres as the resource
but, if the item has not been set this condition always passes:

if item == Resource:

how can I check if the variable is default resource so it does not pass? Kinda like if item == null?

I have used
if variable in item:
to make sure its not the default one, but feels sketchy. sometimes the item might not have that variable

what about this:

var item: Resource = null

if item == null:
    return

EDIT: or are you talking about having a default resource set and seeing if that changed?

Hmm. Of course. thanks! :smiley:
Seems like this would solve both problems indeed

Is there a way to check if default value has been changed though? Like check if is just a “placeholder” default Resource object? purely by method

i dont think this is possible without an extra variable:

var changed: bool = false
var item: Resource = null:
    set(value):
        changed = true
        item = value

if changed == true:
    print("item is not original")

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.