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

Hello I working at a sort pipe game for a game jam and i created a class for determine where to put a bunch of area2D nodes to collide with the pipe(in the game you ll have to drag the pipe and the area2D is like a magnet) but the problem is when i use an instance of the class in the tilemap script(if i use the class script it works). From what i seen it enters in methods but they dont change nothing. What I can do?

class_name Grid_System
extends TileMap

#the tile size of the grid
var _tile_Size : Vector2

#the half of the tile size to center it 
var _half_Tile_Size : Vector2

#the grid size
var _grid_Size :Vector2

#where the grid start on the map
var _grid_Start:Vector2

#the offset needed to allign the grid with the background
var _offset : Vector2

#helps create the grid
var _grid : Array

#helps getting the position of the anterior created grid
var _positions : Array

#setter for the half/tile set
func set_Tile_Size(tile_Size : Vector2):
    _tile_Size = tile_Size
    _half_Tile_Size = tile_Size / 2

#setter for the grid size depending on the room
func set_Grid_Size(room : Vector2):
    _grid_Size = room

#setter for the grid starting position depending on the room
func set_Grid_Start(room : Vector2):
    _grid_Start = room

func set_Tile_Offset(offset : Vector2):
    _offset = offset

#creates the grid and save its positions in the positions array
func create_Grid():
    for x in range(_grid_Start.x + _grid_Size.x):

        for y in range(_grid_Start.y + _grid_Size.y):
            if(y>=_grid_Start.y && x >= _grid_Start.x ):
                var grid_Pos = Vector2(x,y)

#creates a area2D for future collisions checks
func create_Collider():
    for pos in _positions:
        #creates a area2D node add pos it on center of the tile
        var area =
        area.set_position(map_to_world(pos) +_offset - _half_Tile_Size) 

        #create a circlrhape2D to be added to the collision shape
        var shape =

        #create a collisionshape2D to be added to the area
        var collision =

extends Grid_System

#create an object of type grid_system
var grid =

func _ready():

    #set up the tiles offset/size and grid start pos/size

    #create grid and colliders

extends Node

#grid offset to be in centre
var tile_offset : Dictionary = {
    "Oxigen_Room": Vector2(-9,3)

#grid starting position
var grid_Start_Pos :Dictionary = {
    "Oxigen_Room" : Vector2(12,4)

#grid starting position
var grid_size :Dictionary = {
    "Oxigen_Room" : Vector2(6,5)
Godot version 3.4 stable
in Engine by (54 points)

1 Answer

+1 vote
Best answer

WHat do you mean "they don't change nothing" ?
What happens ? Is anything created, is this "here" printed there ??
You must provide some more informations.

But without those informations I can see that You never set "positions" variable, that determine your colliders creation. If it is empty, obviously nothing is created :)

by (8,188 points)
selected by

Yes it prints here but everything else is skipped it the debugger the setter doesn't change anything and at the point of calling create grid an collider everything is 0. Referring to positions idk what you mean in the create grid method i save in positions every position that I need to save. I mean for testing purposes I put the ready() in the and attach it to the tilemap and it works

What is 0, what values ? It prints "here", does it print "made" ? Did You check remote tab, if any objects were created ?

Or could it be, that You only call those from script and don't have GridSystem in scenetree? You realize ready() is called after node is childed, not after it is created with new() ?

Ok I just added as i child thank you it's silly now that I didn't thinked of that.

Haha it is OK, I am glad it occured to not be so complicated :)

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.