Clicking on spawner not reliably spawning units with selection box

the OnPointerClick in UnitSpawner should be working independently of the Mouse input testing in UnitSelectionHandler but for me the click to spawn seems unreliable, only working randomly. Is the click sometimes blocked by the DragBox? I can’t see any difference in the code on gitlab.

So I did some testing and nudging the selection box a pixel to the right prevents the issue from occurring. Wondering if anyone else sees this.

// nudging the box a pixel to the right to prevent occluding the spawn click
unitSelectionArea.anchoredPosition = _startPosition + new Vector2((areaWidth / 2) + 1, areaHeight / 2);

And note I can reproduce this problem on commit 03c94589 (" 9 Selecting Multiple Units") on the gitlab repo.

edit looks like Nathan spotted this at the end of the lecture and removed the Graphics Raycaster from the UnitHandler Canvas, which fixes it. Will be experienced at the end of the previous video though, which might be worth a note.

9 Likes

It’s not often I get a chance to find a solution somebody else posted! Thanks for this.

Privacy & Terms