Casting Controls From Player to Equipped Actors

Ahoy masters of the Unreal.

I have run into a slight problem when coding a designed ‘inventory’ system that is likely a simple problem.

Essentially I am trying to allow players to equip their choice of item to their choice of hand prior to a game. This is easy enough to store the variables and spawn the correct actors to the correct sockets on the player model. I have had no issue getting a character to equip the proper item in the proper hand and I thought all was right in the world.

That was until I equipped a flashlight actor into my character’s hand and realized I had no idea how to control the flashlight from the character blueprint. I worked on the issue, and decided I could ‘Cast’ my custom ‘toggle’ event to the flashlight, and have the flashlight blueprint actors respond by toggling the visibility of the spotlight parented to the flashlight.

Again, I felt like I had solved the biggest problem in the world and life was good.

Until I considered the very design of my solution and the other elements of the inventory choices. My character’s toggle, while coded generic so as to work with any toggle-able item… specifically casts to the ‘flashlight’ actor. So… if I press the button any flashlights in my hands will toggle, but a lighter for instance will not.

I have considered the issue, and decided I need to ‘Cast’ to whatever actors is equipped to the proper socket, which means I need to ‘Get’ currently spawned actor parented to the chosen socket instead of directly referencing the specific equipment item.

The problem is, I am not sure how to do this exactly. Theoretically I can conceive how it could be done, but I am not familiar enough with the options in Unreal or coding in general to know where to start. I seek thine help masters of the Unreal.

The final result I want to have, is left click activates the item in your left hand, right click activates the item in your right hand, and those both activate the proper custom events needed to operate everything from toggled items like flashlights, to one shot go items like a firearm, and holding down for active toggle.

Appreciate the help in advance!

~VGNEVAR

Through further research and feedback from another coder, it seems like in most first person work, the gun’s variables and control are set as functions under the character’s blueprint. It seems like that is an inefficient way to accomplish the goal I intend, but it is the only solution I have been able to find.

No one here has any idea on how to cast inputs to actors attached to player ‘sockets’ instead of coding the items into the character itself?

You are using the word Cast in a strange way. It is not unique to Unreal, it’s part of the terminology for Object Oriented Programming.

Look up Interfaces. You probably want an Interface with a function called Use, or Activate, or ToggleUse. Name whatever you want. Now each of your items should implement the Interface and provide their own unique solution when it’s called. That way, you don’t have to know what the object is and can avoid casting.