Calling a function in another class in UInputComponent::BindAction function

so im trying to have doors open up whenever I press the E key. I have two classes, a class for the door (which has the function to open it) and I have a player class which I have the input component attached to.

Now inorder to bind keys to functions I would use the BindAction function where the last parameter ur supposed to put a reference to the function to be called. the thing is the function is in the door class, so I tried to make an instance of that class in the player class and call It from there but I keep getting “& requires l-value” error.

I don’t know what to do. I could attach the input component in the door class but because the player class will also do other stuff that needs the input component i don’t want to repeat what i don’t have to

Line 43 is just a syntax error not an error in concept. You don’t put the () on &UWorldInteraction::_OpenDoor. The () are reserved for actual calls which is not actually happening in a bind. It is only setting it up.

Thank you for the help, I figured it out.

Just get a pointer to the door and get its class using FindComponentByClass<>() then just call the open function from there.


Note: that the door needs to have a collider with physics enabled and with a PhysicsBody ObjectType because im only triggering this when raycasting in the grab function

@Blacksting thank you for clarifying that I had a syntax error, but removing the () doesn’t fix the problem. Thank you for trying though, I appreciate it

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms