Created
April 9, 2023 01:04
-
-
Save CoffeeVampir3/2a535d4212b64510f3e29da887b5abaf to your computer and use it in GitHub Desktop.
Example interface in Unreal Engine 5.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AActor* ActorToUse = /* Get the actor that implements the ItemInterface */; | |
if (ActorToUse && ActorToUse->GetClass()->ImplementsInterface(UItemInterface::StaticClass())) | |
{ | |
IItemInterface::Execute_Use(ActorToUse); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ItemActor.h" | |
AItemActor::AItemActor() | |
{ | |
PrimaryActorTick.bCanEverTick = true; | |
} | |
void AItemActor::Use_Implementation() | |
{ | |
// Default C++ implementation, can be empty if you want to force Blueprint implementation only | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "CoreMinimal.h" | |
#include "GameFramework/Actor.h" | |
#include "ItemInterface.h" | |
#include "ItemActor.generated.h" | |
UCLASS() | |
class AItemActor : public AActor, public IItemInterface | |
{ | |
GENERATED_BODY() | |
public: | |
AItemActor(); | |
UFUNCTION(BlueprintNativeEvent, Category = "Item") | |
void Use(); | |
virtual void Use_Implementation() override; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "CoreMinimal.h" | |
#include "ItemInterface.generated.h" | |
class IItemInterface | |
{ | |
GENERATED_BODY() | |
public: | |
UFUNCTION(BlueprintNativeEvent, Category = "Item") | |
void Use(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment