Can I somehow work around cyclic resource references?

Godot Version

Godot v4.4.stable.mono - Ubuntu Core 24 on X11 - X11 display driver, Multi-window, 1 monitor - OpenGL 3 (Compatibility) - Mesa Intel(R) Graphics (ADL GT2) - 12th Gen Intel(R) Core™ i7-12700H (20 threads)

Question

I’m trying to make a 3d tilemap system using gridmaps and I want to be able to create the tilesets in the inspector.

I have it so a tileset can either be a group of other tilesets, or it contains tiles which in turn have conditions that determine which tilesets that it can connect with.

Problem is that if I want a tileset to be able to connect with itself, I need a recursive reference. Is there any way I can achieve this, work around the error, or if I should re-think?

Thanks!

A tileset that contains itself would be infinitely large due to the recursion. What exactly are you trying to do?

The tile condition only needs a reference to tilesets so it can check whether or not tiles can connect to it. It shouldn’t have to be infinitely large seeing as it’s only a reference

I also found Allow circular dependencies/references for resources in export var · Issue #7363 · godotengine/godot-proposals · GitHub where people are comlaining about it so I guess it’s currently impossible :frowning: So question remains if I can work around it or re-think.

Let’s say you have A, B, and C.

A references B and C.

 A
/ \
B C

Now you want to link to A as well. A already has links to B and C, so you’re going to get those twice. But it also links A, so you’re going to get everything it contains too.

   A
 / | \
B  A  C
 / | \
B  A  C
 / | \
B  A  C
 / | \
B  A  C
 / | \
B  A  C
etc.

That’s how recursion works. If you want it to be non-recursive, that would work, so you only go one layer deep. But then if say B also contained D, you wouldn’t get D.

However A should already know about itself. It doesn’t need to be connected to itself. It already is itself. My suggestion is you just examine why you think a tileset needs to be connected to itself.

I guess I could have a special type in the condition that tells the tileset that it’s supposed to be itself. Problem is if I’m using tileset groups.

Tileset group
|-- Tileset
| |-- Tile condition (With “self” type instead of reference)

In that scenario the tile whouldn’t know if it’s refering to the tileset or the group that the tileset is a part of. I probably could have like a number how far up the heirarchy to go, but it feels like such an unesessary layer of complexity that could make things difficult in the future. I guess it’s what I can do in the mean time. :confused:

I recommend you read up on recursion. It’s a functional programming concept that’s very useful in this type of situation. What you want to do is write a recursive function. First it runs on resource A, and then all its dependents. That way it doesn’t need itself as a dependent.

An example in the Godot documentation is in the import script section.

Another example you can google is how programs search directories for a file.

Is there ever a scenario where you wouldn’t want a tileset to be able to connect with itself? It seems to me like either you can simply make it implicit that a tileset always connects to itself, or you can assume it does and have a flag to override that. Either way gets you out of the self-referential loop.