Problem with Cursor Affordance for newly created NPC layers - Cursor wont change for newly created layers

https://www.youtube.com/watch?v=3ICLvlIsn6w

I am trying to add new cursors on mouse hover for Intractable NPCs (you can open dialogue with these npcs in future) and Friendly NPCs (where cursor just turns to green, they just exist in the world). In Utility.cs I went ahead and added two additional enums as follows.

public enum Layer
{
    Walkable = 8,
    Enemy = 9,
    NPCInteract = 10,
    NPCFriendly = 11,
    RaycastEndStop = -1
}

New tags were created in Layer 10 and 11
Screenshot_6

So in CursorAffodance.cs the switch statement was updated to

void OnDelegateCalled (Layer newLayer) {
        switch(newLayer)
        {
            case Layer.Walkable:
                Cursor.SetCursor(walkCursor, cursorHotspot, CursorMode.Auto);
                break;
            case Layer.Enemy:
                Cursor.SetCursor(targetCursor, cursorHotspot, CursorMode.Auto);                
                break;
            case Layer.NPCInteract:
                Cursor.SetCursor(npcInteractCursor, cursorHotspot, CursorMode.Auto);
                //Debug.LogError("On NPC");
                break;
            case Layer.NPCFriendly:
                Cursor.SetCursor(npcFriendlyCursor, cursorHotspot, CursorMode.Auto);
                break;
            case Layer.RaycastEndStop:
                Cursor.SetCursor(unknownCursor, cursorHotspot, CursorMode.Auto);
                break;                
            default:
                Debug.LogError("Dont know what cursor to show!");
                return;
        }        
	}

New cursors were attached/assigned as required

And this NPC is tagged with the appropriate tag
Screenshot_8

Now, I have to mention that to create this NPC I skipped ahead and watched
Lecture 54. Importing Humanoid Animations of Section 2, Importing Humanoids. I followed steps in the video and changed an enemy character into this new humanoid. Now when I retag the NPC as an enemy the cursor changes to the assigned enemy cursor, but with the newly created NPC layer, no change happens. What am I missing in this case, as this new humaniod npc seems to have cursor working for the enums that were created in the course, but my own additions dont seem to take change.

Hi,

Can you pop a screenshot up of the Inspector with the CameraRayercaster script component attached, with the layers displayed please.

Heres the screenshot.

Screenshot_9

Thanks.

Move the Walkable layer to Element 3 and set NPC Interact to Element 1, and NPC Friendly to Element 2.

Try the game again and see if you notice any change.

Ah cheers Rob, that solved it. I took that element for granted.
I am lost though as to how that order fixes / breaks things? Because in my CameraRayCaster.cs
I still have in this order

public Layer[] layerPriorities = {
        Layer.Enemy,
        Layer.Walkable,
        Layer.NPCInteract,
        Layer.NPCFriendly
    };

and now works as intended.

Hi,

No worries, happy to help.

The list in code only matters if no options are set in the Inspector. The Inspector over-rides the code.

The list is an array, so when the array is iterated over, the order in which these are set matters, as you want it to find some before others.

Hope this helps and glad you can move forward with your project again :slight_smile:

1 Like

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

Privacy & Terms