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.

godotengine.org | Twitter

+1 vote

Background info:
I am using a tilemap layer to keep track of available tiles. This way I can also toggle the visibility of that layer to show the player what tiles are available.
When I delete a tile I use the this function:

func clear_tile(tile):
    get_node("TileMap").set_cell(3, tile, 2, Vector2i.ZERO)

which causes this error:

Condition "!Q" is true.
  <C++ Source>   scene/2d/tile_map.cpp:2100 @ set_cell()

which relates to this part of engine code:
https://github.com/godotengine/godot/blob/92bee43adba8d2401ef40e2480e53087bcb1eaf1/scene/2d/tile_map.cpp#L2100

As far as I can see I am using the set_cell function correctly, and I don't understand why this error is thrown. I get *when* the error is thrown, just not *why* the programmers decided it is needed. I am doing exactly the same as the function

void TileMap::erase_cell(int p_layer, const Vector2i &p_coords)

which also throws the same error.

Question:
What is the "!Q is true" error for and will it actually cause any problems?

Note:
I know there are ways I can avoid needing to erase tiles (like making the tiles transparent instead), but I think my current solution is good for simplicity and code clarity.

Godot version 4.0-stable_mono_win64
in Engine by (197 points)

1 Answer

0 votes
Best answer

When does the error happen?
When set_cell is used on a cell in a disabled layer. The erase_cell function is really just a call to set_cell, so it produces the same error.

Why does the error happen?
It is essentially an early return to prevent bigger errors. The Condition "!Q" is true. error is thrown, preventing the engine going ham on null.

What does the Error mean?
The engine creates "stuff" to handle layers. When a layer is disabled, the engine removes the "stuff" it made to handle it (the "stuff" is remade if/when the layer is enabled again).
Layers are partitioned into quadrants as part of the "stuff"-making process. In the Condition "!Q" is true. error message, Q is a pointer to a quadrant. If the relevant layer is disabled, then Q is pointing to null(since there is no "stuff"). That is exactly what Condition "!Q" is true. means ("There is no 'stuff' to manipulate.").

Will this error cause any problems?
I don't think so. The set_cell function changes the cell in the layer before the error happens, so it does what you would expect. Once the layer with the cell gets enabled; the "stuff" will be made using the layer and it will be the same as what you would get if set_cell is used while the layer is enabled.

by (197 points)
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.