• Godot Help
  • i dont understand why i get the "nul instance" error

hello so i have done this : @onready var max_dist = $CollisionShape2D2.shape.radius
but it says to me : invalid get index "shape" (on base : "null instance")

also it did work in godot 3 but since im using godot 4 it dont work in both vertion even tho it is she same project i did a backup for godot 3 so it is not the same file for godot 3 and 4
if you have any idea thank you to reply 🙂

  • Dagunov replied to this.
  • ok so i redo this part of the project in an new project and it worked i'm going to redo the whole project by hand if sommone read this and had the same issue i just hope for you your projrct is not big

    The error means that $CollisionShape2D2 is not a valid node reference.

    Try adding this, and post the output:

    func _ready():
        print_debug("CollisionShape2D2=", $CollisionShape2D2)
        print_tree()


    just in case you cant see the outpout it say : CollisionShape2D2=[Object:null]
    At: res://script/utilitaires/joystic.gd:3:_ready()

    That confirms that the node reference is null.

    The "." output from print_tree() means that, when _ready() is run, the node (to which that script is attached) has no children. In particular, it has no child named "CollisionShape2D2".

    cianguild Hi! Down in "Errors" you can see that your problem is not only with CollisionShape2D2, but also in rows 2 and 3. I think something is messed up in the scene tree - can you post its screenshot here?

      sorry i do this in godot 3 here the godot 4 vertion

      and here it says the same thing i guess :CollisionShape2D2=<Object#null>
      At: res://script/utilitaires/joystic.gd:3:_ready()

      That node name is CollisionShape2D, not CollisionShape2D2.

      But I don't understand why the print_tree() didn't show the children.

      Is it possible that the script is attached to more than one node in your project?

        DaveTheCoder
        the 2D2 was in godot 3 (somthing that i tried) but no i dont think it is linked to more than 1 node
        the only way i see it coud is if the 2 project are linked in a werd way (i steel look just in case)

        ok so i redo this part of the project in an new project and it worked i'm going to redo the whole project by hand if sommone read this and had the same issue i just hope for you your projrct is not big