Autotile Between Different Tilemap Nodes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Darzall

I’ve been working on a way to create tilemaps from a template dynamically based off a json file. Got it working decently so far, however I’ve run into the problem of the tilemaps (despite the nodes all being copies effectively of one another) not binding to eachother for autotile.

Have binding code (admittedly in gdscript still from tutorial I snatched it from) for autotiles within the same tilemap working…as shown between the ground-dirt and ground-stone tiles in the image below. Just not sure how to deal with the autotiling between different nodes in a ‘clean’ way.

Worst case alternative is being forced to create individual images/tilesets for each variant on the tiles, which I really would rather avoid for my own sanity, and keeping my file system non-bloated.

Alright, so I spent some time messing around with the binds code (and thus converted it to C#). Thought at first I could create a global variable with the node paths in an array, for the various walls that need binding to one another. Issue #2 is there is no _Ready in the Tileset code…

Then thought that maybe I could just manually search for the corresponding walls. Issue #3, no way to use GetNode even from within the _IsTileBound.

I am honestly even more stumped then before?

Darzall | 2021-08-10 11:12

:bust_in_silhouette: Reply From: Darzall

I did it! Or at least a semi-workaround for now…my god was this frustrating.

For those interested in the workaround:

   // Resets local bitmask to global template's bitmask (should be a combination of all duplicated nodes' cells):
public void ResetGlobalBitmask(Vector2 region)
    var usedTemplate = Globals.WALLTEMPLATEMAP.GetUsedCells();
    var used = GetUsedCells();
    Array[] usedIDArray = new Array[autotileID.Count];

    // First, for each autotiled ID in tileset add to array to check later:
    foreach (int id in autotileID)
        GD.Print("Reseting bitmap of " + Name + " with ID " + id + "...");
        usedIDArray[id] = Globals.WALLTEMPLATEMAP.GetUsedCellsById(id);

    // Next, scroll through the wall template region, copying it to the current wall node, then update bitmask:
    foreach (Vector2 vector in usedTemplate)
        var index = 0;
        foreach (Array cellArray in usedIDArray)
            // Checks between different autotiled tiles to set correct tile index:
            if(cellArray.Contains(vector)) SetCell((int)vector.x, (int)vector.y, (int)autotileID[index]);
    // From testing, need to reset the bitmask from outside the foreach before resetting local used cells:

    // Reset current wall node back to its own used cells (do not update the bitmask again after this, unless rerun):
    foreach (Vector2 vector in usedTemplate)
        if(!used.Contains(vector)) SetCell((int)vector.x, (int)vector.y, -1);