Hi, I can’t seem to find a solution to this other than something a bit roundabout, so I wanted to see if anyone would know the solution.
I have a character class and an arm class that is attached to it. The arm is a component and has a couple of functions I’d like to reference in the character class via its input action binds. I know I could make several player functions that just call the arm functions, but it seems like I shouldn’t have to do that.
Currently I’m getting an error stating it isn’t a viable function. The arm h file is included in both character files. I’ve tried making it a friend, but that just results in a cannot resolve symbol error.
Any help would be super appreciated! Running Unreal 5.4.4 and JetBrains Rider.
What is the actual error message? C++ error message are actually pretty good if you read and dissect them. Well, not templates but that’s not in play here.
I have a suspicion, but would need the whole error to confirm.
This is the viable error
And this is the friend error
Okay, that’s not actually a compile error. That’s Rider trying to be helpful. You can’t always trust those squiggles because Rider isn’t always up to date on something. I will often have squiggles about missing function implementations that go away after I compile or a little time. Also, the actual compile errors you can copy/paste into a post in a way that’s more helpful to the people that are helping you. Just FYI for the future.
But in this case it’s fine.
So it’s telling you that the arguments don’t match. The first list is the arguments that you’re passing in: char[10]
, EInputEvent
, TObjectPtr
and the function pointer. C++ types make this a little difficult because of implicit conversions, but each one of the “Candidates considered” is telling you exactly that it can’t match the UserClass* Object
parameter type to the TObjectPtr< >
type of your member variable. This is because there’s no built in conversion operator for that so you’ve got to call the Get
function on TObjectPtr
to get a raw UarmComponent*
that you can pass to that function. Sorry, that reasoning is wrong because there is a built inconversion to the raw pointer. What’s happening here is that template type deduction is failing because the template doesn’t know how to deal with a parameter that isn’t a pointer to figure out the type.
You have two options: Use the Get as I initially suggested or be explicit with the type so:
PlayerInputComponent->BindAction( "Blah", IE_Pressed, ourArm.Get(), &UarmComponent::PunchArm);
or
PlayerInputComponent->BindAction<UarmComponent>( "Blah", IE_Pressed, ourArm, &UarmComponent::PunchArm);