Download

How do I get different actor tags to do certain things?

Hi, I’m trying to make an interact system using a line trace from where you’re looking, and I want it to check the hit actor for its tags, then depending on what it’s second tag is it will perform a certain action.

All interactable objects have at least 2 tags, the first one is called ‘Interactable’, and the second depends on the item, for example a lockpick door’s second tag will be ‘Lockpickable’, an item you loot’s second tag will be ‘Lootable’, a lever’s second tag would be ‘Pull lever’. I want it so the line trace hits an actor, gets a copy of its second tag, then plug the result into a node which has a list of potential second tags, so you plug it into the node then depending on what the what the name of the tag is it will have a different output. Does such a thing exist? If not, how would I do it?

I’ll try and draw out what I mean to make it more clear.

Also, while I’m at it because it’s part of the same system, does anyone know why this doesn’t work? If the door is ‘unlocked’ from the start, I want it to automatically remove the ‘Lockpickable’ tag from its list of tags, so at the end of the Event Begin Play I called the function ‘Unlocked’ which is meant to do just that, but it doesn’t remove the tag and I’m not sure why because when I actually go through the lockpicking and unlock the door that way, it works, the only difference is if I actually unlock it through lockpicking the ‘Unlocked’ function is called from the ThirdPersonCharacter_BP, whereas this image is from inside the door BP, so if anything calling it from the ThirdPersonCharacter_BP should be the one to not work, not the one calling an event from its own blueprint.

I tried using a delay of 0.1 seconds just in case the reason was it was trying to remove it too quickly but that didn’t change anything.

Anyone able to help?

Switch on Name … [Switch on Name | Unreal Engine Documentation

](Switch on Name | Unreal Engine Documentation)

You’re a legend, thank you so much! I think at this rate I’m gonna have to credit you in my game you’ve helped me with that much, haha

I did this in a more flexible way myself. I added a “Usable” component to any actor that is interactable.

The component can have a custom message so you can say, “Press E to <Insert custom message here>” on any arbitrary object.

And I can bind an event to when the player actually used it. The event would have the actual logic.

This way it’s possible to add infinite types of interactable objects and you’re not bound by a hardcoded switch statement.

Then your all your locks in the game can be subclasses of a common Lock class that has the code for being lock picked.

All your lootable objects can be subclasses of a common lootable class.

All your switches can be subclasses of a common switch.

Etc…

And you can even do things in the level blueprint. I did one example where I created a random actor and when my player interacts with it, it triggers a scripted event in the level blueprint.

And now your character isn’t going to have a giant difficult to manage switch statement for every type of interactable object in your game that you may have or potentially keep adding.

Thanks, I’ve just tried that but I have no idea what I’m doing, would you be able to show me what you mean please?