I am relatively new to UE4 and blueprints so sorry if the answer to this is obvious. I am building a computer game kind of like PC Builder Simulator.
I am trying to build a use system. My issue is that some actors I need to pick up, and other actors I need to “use”. I have a widget that displays a message like “Press ‘E’ to pickup” and I can pick up objects, but now I need that to dynamically change depending on the type of actor it is looking at.
For example… if the player looks at a computer case, it should read “Press ‘E’ to pick up”. If I am looking at the power switch on the computer case, it should read “Press ‘E’ to Power On”.
I am unsure of how to go about this. I thought about adding a string variable for the computer case called “Action” but if I can’t figure out how to access that from my player blueprint.
Here is my current blueprint for displaying my widget and allowing the player to pick stuff up:
You need to use blueprint interfaces. With this, you can say to the actor ‘I’m looking at you’, and the actor can respond in any appropriate way. Including returning the type of ‘use’ command.
Next I created a parent class called “InteractiveObject”. I added a string variable called “UseType” with a default of “Grab”, and I in the Event Graph I setup a Event Hit that would check to see if the hit object implements my “UseTypeBPInterface”, if it does then I would pass the current objects “UseType” string variable:
I use a collision sphere with a mesh child component. On overlap begin (collision sphere) → do things… render text etc.
In the character class I simply set the interact input (E) to get all overlapping actors of class (interactive object) → uses interface (), branch … cast to interactive object → get type → call event.
So basically the text shown (Pickup/Power on) tells the user there can be interaction. Pressing E executes its functionality.