I made an InputAction called Interact. When I press E, it will fire off the Interact node. But it stops at the Cast to NPC node. NPC is a Blueprint actor I created with a Boolean PlayerCanInteract. The ToggleVisiblity is there to test if this works or not. After I press Interact, shouldn’t it then check PlayerCanInteract is true and if it is, toggle visibility of the NPC mesh?
Where do you put this code? If it’s in player character blueprint, certainly GetOwner does not return any NPC.
If you’re trying to use E to toggle the visibility of your NPC from your main player, you’ll need:
For more than one NPC:
It’s in the player character.
To put it simply, if PC is near the NPC (overlapping its sphere collision), the PlayerCanInteract boolean is set to true, and when I press E, it fires off the Interact InputAction that does some function. In this case, toggles the NPC’s visibility.
What I don’t get is how to get the specific instance of the NPC that the PC is overlapping with.
You can use ActorBeginOverlap and store OtherActor as the current NPC (if it’s an NPC via a cast) and ActorEndOverlap to set the NPC to NULL in player character blueprint.
Another way is to use ActorBeginOverlap and ActorEndOverlap in NPC blueprint. If the OtherActor is player, you can use an event in player character blueprint to set (and unset) current NPC.