Unreal Engine 4.x Scripting with C++ Cookbook - Second Edition
by John P. Doran, William Sherif, Stephen Whittle
How it works...
As in previous recipes, we mark UFUNCTION as BlueprintNativeEvent and BlueprintCallable to allow the UInterface to be implemented in either native code or Blueprint, and allow the functions to be called with either method.
We create DoorBell based on StaticMeshActor for convenience, and have DoorBell implement the Interactable interface. Inside the constructor for DoorBell, we initialize HasBeenPushed and DoorToOpen to the default safe values.
Within the implementation for CanInteract, we return the inverse of HasBeenPushed so that once the button has been pushed, it can't be interacted with.
Inside PerformInteract, we check if we have a reference to a door object to open. If we have a valid reference, we verify that the door ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access