Calling a function from actor component for Enhanced input inside Player Controller

Hello, Sorry if this is a novice question. But I’ve been trying to find a solution to this to no avail.

So basically I have my Character, the Character is controlled by a Player Controller, and on the Character is an Actor Component I set up for interactions (Line trace) and a few functions to handle the results of the trace.

The issue I have now is that I want to bind the F key as my “Interaction” key (I’ve made the Input Actions and added it to the Mapping context) but when I set up the logic inside the player controller for “Begin Interaction” and “End Interaction” it says it can’t do it because the functions are “protected” with-in the actor component.

Is there a way around this? or must I move the function logic from the actor component to the player controller?

Disclaimer: Missing some details, if my assumptions are incorrect please add some screenshots of your blueprints so that we can understand the context better.

If I understood correctly, you created some logic in your component A’s graph which is now inaccessible in your actor B’s graph. If this is your logic (and not something built-in), you should be able to (see image) set its “Access Specifier” to Public, which will allow you to call it from other blueprints (including your controller).

Sorry let me see if I can better explain.

In my actor component I have created a function that deals with the interaction line trace

and I have all inputs mapped with-in the Player Controller, but when I attempt to call it with-in the player controller It says the function is protected.

Hey @BoostedCR24!

I think there’s a confusion on inheritance. The protected access specifier allows member functions to be accessed from derived classes. The player controller doesn’t derive from your actor component. For you to be able to access your function from the player controller, you’ll need to adjust your header file (the image you shared is a screenshot of the .cpp file, not .h), making sure that the first access specifier above your function declaration is the public access specifier, and not protected.

So @Kemichar is correct, just skipped the explanation.

Hope this helps :innocent:

1 Like

@VisAgilis Correct, seeing his post I moved the functions in the .h file to the public section and it worked. I marked his reply as the solution.

1 Like