By the end of this module, I had a project that behaves pretty much the same as the one in the videos, but I noticed one pretty bad defect - the shoot action would only highlight targets which were within range and line-of-sight, but if I clicked on an enemy target further away or behind a wall it would perfectly cheerily take the shot and reduce the health of that enemy anyway.
This was because the IsValidActionGridPosition method was only checking whether the target space contained a unit which was an enemy, not whether or not all the other criteria for a valid shot had been met; the constraints on range and line-of-sight had only been implemented in the GetValidActionGridPositionList method. So the enemy units didn’t take advantage of this because they were deriving their valid targets from the GetValidActionGridPositionList, but this is only used for display when taking player actions and the player can just click anywhere to instruct the game to attempt the action on that space.
I fixed the problem pretty easily by refactoring all the validity checks into a new overload of IsValidActionGridPosition that took two params (the source and the target positions) and calling that both from within GetValidActionGridPositionList to filter the valid spaces and also from the regular override of the base class’ IsValidActionGridPosition, which passed in the action’s owning unit’s position for the first param.
Did I miss somewhere where this issue had been returned to and solved in an earlier video? Or perhaps have I introduced this issue with some other changes somewhere else that I’ve not noticed? I’m coming at this course as a professional C# dev of twenty years who just doesn’t know much Unity, so there’s been a lot of points over the course of the videos where I’ve seen ways to do things I think are better; I’ve tried to just follow the course for the most part as generally these issues have been picked up later in the video or refactored out in a subsequent video and I do understand why the most simple approach is taken at first. But I’m still not sure why the GetValidActionGridPositionList implementations didn’t just offload all the validity checks into IsValidActionGridPosition in the first place!