Action System in Blueprint

Hello Everyone !! I’m new to Unreal Engine, and I try to create an Action system !

I want my player to interact with objects in the scene. First I created a BP Interface with a function that returns an array of “Actions”. At the beginning, an action was just a structure with a name, a description and an icon. But when I needed to execute my action, I was lost.
So I deleted my structure and did the same with a Data Asset ! I created a Blueprint that inherit PrimaryDataAsset, created my variables and added an Event dispatcher called “Executed”. I have also a function that just call that event. Then I create one DataAsset by Action (Pick item, Open Door etc…) But it not contain the action itself. For example I have a generic Actor that inherit the Interactive BP interface, and I manually return an array of actions with my “Pick Item DataAsset”. Then I listen the executed event on that Actor, to do the pick logic.

It’s my Character class that listen inputActions that get the Action (DataAsset) with sphere tracing…

My problem is that when I listen the event of the Data Asset from my Actor Blueprint, I can’t use “GetPlayerCharacter” or “GetPlayerController”, or I can’t “Destroy” on self reference to destroy the item when picked… I’m a bit lost, is it the best way to do that ?

I tried to make a schema :
Thx everyone !

It sounds like you’ve seen way to many tutorials :slight_smile:

All you need is a line trace from the character which looks for objects in the scene which implement the ‘use’ interface.

Calls you can make on that interface could be things like ‘open’, ‘close’, ‘pick up’. The actor can return a list of actions it’s prepared to execute.

If it does ‘pick up’, you can send a message saying ‘picked up’ and it can destroy itself.

Check it out. I made UseBPI, it only contains:

Use actions is an enumerated list:

Then I make a BP that implements the interface, and I can find it from the character like this:

It’s a bit contrived because you would actually change the mouse cursor if the object implemented the interface. If it was a pick up, you would show the ‘pick up’ icon. And when the user clicked ( or whatever ), pick up the object.

So this is sort of doing the whole thing in one go, just as an illustration.

The code in the BP is just :


Thx for your answer !
I didn’t want to have all possible action in my “use” interface, so I just created an “Execute” function with the action as parameter. When I implement the interface, I just have to check the value of “action”, or just ignore it when only one action is available, and it work perfectly !
Thx again to clear my mind !