Created
April 8, 2021 17:30
-
-
Save msmoiz/590d74812347b521ce668cdf070b1f7e to your computer and use it in GitHub Desktop.
Interface Demo for Unreal Engine 4
This file contains 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
#pragma once | |
#include "CoreMinimal.h" | |
#include "UObject/Interface.h" | |
#include "InterfaceDemo.generated.h" | |
UINTERFACE() | |
class UBaseInterface : public UInterface | |
{ | |
GENERATED_BODY() | |
}; | |
class IBaseInterface | |
{ | |
GENERATED_BODY() | |
public: | |
// Will cause a compile error | |
// UPROPERTY() | |
// int32 Variable; | |
// Will compile, but should be avoided | |
// int32 SomeOtherVariable; | |
}; | |
UINTERFACE(meta=(CannotImplementInterfaceInBlueprint)) | |
class UNativeInterface : public UInterface | |
{ | |
GENERATED_BODY() | |
}; | |
class INativeInterface | |
{ | |
GENERATED_BODY() | |
public: | |
virtual void DefinedVirtualFunction() {}; | |
virtual void PureVirtualFunction() = 0; | |
UFUNCTION(BlueprintCallable) | |
virtual void ExposedVirtualFunction() {} | |
}; | |
UINTERFACE(/* Blueprintable */) | |
class UMixedInterface : public UInterface | |
{ | |
GENERATED_BODY() | |
}; | |
class IMixedInterface | |
{ | |
GENERATED_BODY() | |
public: | |
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable) | |
void BPFunction(); | |
UFUNCTION(BlueprintNativeEvent, BlueprintCallable) | |
void BPNativeFunction(); | |
// Will cause a compile error | |
// UFUNCTION(BlueprintCallable) | |
// virtual void ExposedVirtualFunction() {} | |
}; |
This file contains 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
#pragma once | |
#include "CoreMinimal.h" | |
#include "UObject/Object.h" | |
#include "InterfaceDemo.h" | |
#include "InterfaceImplementation.generated.h" | |
UCLASS() | |
class UImplementor | |
: public UObject | |
, public INativeInterface | |
, public IMixedInterface | |
{ | |
GENERATED_BODY() | |
public: | |
void DefinedVirtualFunction() override | |
{ | |
// do something | |
}; | |
void PureVirtualFunction() override | |
{ | |
// do something else | |
} | |
void BPNativeFunction_Implementation() override | |
{ | |
// do something native | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment