CoordinateLabeler can no longer update label colors in Editor mode

In the earlier part of the Realm Rush course the CoordinateLabeler script was able to update not only the coordinate text on the tiles in Editor mode Scene view but also the colors. It would show white text on the labels if the tile was unblocked (isPlaceable) and grey text if the tile was marked as blocked. However, after the refactoring about halfway through where pathfinding and the grid node systems were introduced this no longer functions in Editor mode. The colors get set fine in play mode, but in the Editor they do not update when the “Is Placeable” flag is changed on a tile.

At first, I thought this was just my code. But I have also downloaded the final GameDev.tv project files from Gitlab and ran it only to find out it doesn’t work in the instructor’s version either.

My debugging indicates this is because CreateGrid() is only called in Awake() within the GridManager script. It never gets called in Editor mode, only when the game is running. Therefore, SetLabelColor() in CoordinateLabeler fails to work because all nodes are null (they are only created in Game runtime, not Editor).

So I guess the purpose of my post is twofold. First, to let you know so maybe you can fix this in Realm Rush course. Secondly, to ask how one might solve this? I though perhaps making CreateGrid() a public function and calling it from CoordinateLabeler, but there are problems with this approach.

Hi,

Thanks for bringing this issue up. I forwarded it to Gary, so he will be able to look into this. May I know in which lecture you are?

Regarding the potential bug, I would say: Ignore it for now and complete your game first. The CoordinateLabeler is just a visual help for us game developers. It does not affect the actual game. For this reason, it is fine to fix the bug at a later juncture.

Thanks for the reply Nina. The lecture was Realm Rush within the Complete C# Unity Game Developer 3D Online Course.

I did finish the game before posting this and did also attempt to figure out what was causing it and possible solutions. I would like to emphasize, in case I came off too aggressively, that my post was meant in the full spirit of constructive criticism, as a suggestion. I am very happy with the quality of course material in general. I think it is excellent and I realize all the hard work that goes into not only creating it but trying to support it.

The reason I thought it worth mentioning is because even though as you pointed out, this particular feature is not important for the actual gameplay, I thought it was neat, it was a feature that we had but lost, and most importantly useful to learn a bit about interactions and behaviors during Editor application mode. Even if it is deemed not important enough to revise material in any significant way, which I would understand, I think it might be a good idea to at least drop a mention to students that after the refactoring the label colors in editor mode will no longer change and explain why.

Thanks for taking the time and for being so helpful to everyone.

Hi @cp_clegg, great spot!

You’re right on the money with your debugging. The reason this no longer works is because we moved over to using the GridManager to lookup the state of the nodes and we don’t create the grid until we enter play mode.
This means that when we try to grab the details of a node result will always be null.

There are a few ways around this, but the easiest would be fall back to checking the state of isPlaceable in the Tile.cs in the event that the coordinate labeler can’t find the details about a specific node.

In SetLabelColor(), rather than simply returning if the node check returns null, try something like this:

void SetLabelColor()
    {
        if (gridManager == null) { return; }
        Node node = gridManager.GetNode(coordinates);

//-- Change this part ------
        if (node == null)
        {
            Tile tile = GetComponentInParent<Tile>();
            if (tile != null)
            {
                if (tile.IsPlaceable)
                {
                    label.color = defaultColor;
                }
                else
                {
                    label.color = blockedColor;
                }
            }
            return;
        }
//---------------------------

        if (!node.isWalkable)
        {
            label.color = blockedColor;
        }
        else if (node.isPath)
        {
            label.color = pathColor;
        }
        else if (node.isExplored)
        {
            label.color = exploredColor;
        }
        else
        {
            label.color = defaultColor;
        }
    }

You may want to cache a reference to the tile at the top of the script instead of constantly having to get it off the parent, but I’ll leave that to you.

I hope that helps but if you have any questions, please let me know.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms