Interfaces, events, blueprint interaction, lack of explanation

Hello. I’m totally stack with ue4 c++ programming, my posts remains unanswered and I can’t find any info at all. I’ll try my luck one more time.

  1. Interfaces - what are they, how does they work? I’ve read this article Interfaces_in_C++ but it gives only high level overview without actual real world example. I’m investigating interfaces in strategy game example - there’s UStrategyInputInterface. Why does file have two classes inside (UStrategyInputInterface and IStrategyInputInterface)? Is it a mandatory? Why does method name is OnInputTap() but in implementation it’s called OnInputTap_Implementation()? It seems that this method called on mouse click, but why, who calls this method?

  2. How to listen mouse events in c++?

  3. I’ve created a pawn in c++, added camera component to it, add transform to it. It works. But changing transform of the camera in blueprint doesn’t change anything. Also, changing rotation does’t do anything if you don’t specify bUseControllerViewRotation = falseproperty. How should I know it? Documentation here is not available. Checking all comments for all fields?

Best regards.

I can help answer the Interface question.

An interface is merely a contract. You’re saying that you’re expecting a certain method or group of methods to be part of the class that implements that interface.
For example, you can have characters that don’t necessarily inherit form the same class, but you know that they all need to be able to TakeDamage(float Amount) (for example). Exactly how that happens or what’s inside that method is irrelevant, so long as the signature matches that of the Interface. Likewise, you could have Furniture, for example implement that interface, and yet again handle it completely differently.

If you continue reading on the article you linked, there’s an actual example. In C++, interfaces and mutli-inheriting go hand in hand.

While I don’t have the example project installed on my computer, based on the wiki, I’m assuming UStrategyInputInterface is inheriting from UInterface, which appears to be a requirement for UE4, and does not appear to be required.

As for mouse events, you set them in the editor’s Project Settings -> Inputs. Action Mappings -> whatever mouse event you’re looking for.

Then, in your code, you can map them via a UInputComponent->BindAction(const FName ActionName, const EInputEvent KeyEvent, UserClass* Object, typename FInputActionHandlerSignature::TUObjectMethodDelegate< UserClass >::FMethodPtr Func)

Thank you for an answer. I know what is interfaces from another languages that supports it out of the box. But I’m still wonder of ue4 c++ implementation. For example, in the ling that I posted there’s a header file with

class UToStringInterface : public UInterface


class IToStringInterface

and this UToStringInterface is not used anywhere, so why to declare it?

Regarding mouse events I mostly interested how to listen for concrete mouse events for concrete actors, something like


I can’t find anything similar - no examples, api reference not available, vs intellisence is not working :frowning:

Exactly my thoughts. Then from lack of info i do mistake and whole thing crashes. :smiley:

Ok, so I found that there’s actually OnClicked delegate in AActor. But how to use it? When can I get signature for this delegate and how to setup all the stuff?

Next small step. In Actor.h I found declaration of OnClicked - code says that delegate function should be without parameters. It works now.
For testing I also added delegate to collision component of my actor - it have different signature. But it’s not working. Can anybody explain why?

The comment right above the declaration explains why you declare it at all:

/** Class needed to support InterfaceCast<IToStringInterface>(Object) */

Then, two topics after it explains what InterfaceCast is and why you may want to have it.

This is the one quirk specific to the UE4 API that I can see when it comes to Interfaces, but it has some added value, so it works out.