The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I get an error, set cell on null instance:

extends Node2D

var randNumber : int 

func _ready():
    randNumber = randi() % 100 + 1

    var wall = get_node("../TileMap")
    var grass = get_node("../TileMap2")

    if randNumber > 50:


I also tried with: - after extends Node2D, same error

onready var wall = get_node("../TileMap")
onready var grass = get_node("../TileMap2")

so... how to put a child node in a variable?
I know, I could just go in and do $TileMap.set cell and $TileMap.updatebitmaskarea and it would work but I'm used to put everything in a variable.

Godot version 3.3.2
in Engine by (173 points)

If TileMap and TileMap2 are childnodes of the node with this script, you should leave out the ../ and use get_node("TileMap") and get_node("TileMap2").

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.