mapeditor / mapeditor/tiled

`Tile.objectGroup = new ObjectGroup()` does not show group in collision editor till different tile is selected

Open
#3,655 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
12.9k
Forks
2k
Avg merge
4h 27m
Merged PRs (30d)
8

Description

Describe the bug

When a script programmatically adds a new ObjectGroup() to a tile, then adds shapes to that tile.objectGroup, it does not appear in the Collision Editor. It can be made to appear by switching to a different tile, then back to the original tile.

If collision shapes are added in the collision editor before the workaround described above, it seems like the collision editor replaces the scripted objectGroup with a new one.

It seems like the collision editor UI is not notified about the addition of an objectGroup via scripting.

To Reproduce

Steps to reproduce the behavior:

Add the following script to a project:

const setupCollisionActionId = 'setup-collision-action';
const setupCollisionAction = tiled.registerAction(setupCollisionActionId, (a) => {
    const tileset = tiled.activeAsset;
    if(tileset.isTileset) {
        const tileset = tiled.activeAsset;
        const [tile] = tileset.selectedTiles;
        if(tile.objectGroup == null) {
            tile.objectGroup = new ObjectGroup();
        }
        const point = new MapObject('origin');
        point.shape = MapObject.Point;
        tile.objectGroup.addObject(point);
    }
});
setupCollisionAction.text = "Setup Collision";
tiled.extendMenu('TilesetView.Tiles', [{
    action: 'setup-collision-action'
}]);

Open a tileset with at least two tiles, that do not have any collision shapes in the collision editor.
Select the first tile.
Open the collision editor before the next step.
Right-click the tile, click "Setup Collision" to run the scripted action.
Observe that the collision editor does not show the new Point
Click the second tile in the tileset, then click back to the first.
Observe that the collision editor is now showing the new Point

Expected behavior

When scripting adds an objectGroup to a tile, it should appear immediately in the collision editor.

Media

Animation

Specifications:

  • OS: Windows 11
  • Tiled Version: 1.10.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided tiled.registerAction script, tile.objectGroup, and Collision Editor workflow. Trace how the Collision Editor refreshes when an objectGroup is added through scripting, then verify that the new Point appears immediately and that existing scripted shapes are preserved without switching tiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, javascript
Domain
desktop, game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.