这一节来说,相对容易,在蓝图中把C++类的接口进行实现。
首先在C++中创建接口,并定义一个方法showinfo,返回值类型为bool,意思是函数,不是事件。
UFUNCTION的宏定义改变成BlueprintImplementableEvent,意思为蓝图可实现的事件。
1 // Fill out your copyright notice in the Description page of Project Settings.
2
3 #pragma once
4
5 #include "CoreMinimal.h"
6 #include "UObject/Interface.h"
7 #include "MyInterface.generated.h"
8
9 // This class does not need to be modified.
10 UINTERFACE(MinimalAPI)
11 class UMyInterface : public UInterface
12 {
13 GENERATED_BODY()
14 };
19 class MYPROJECT9_API IMyInterface
20 {
21 GENERATED_BODY()
22
23 // Add interface functions to this class. This is the class that will be inherited to implement this interface.
24 public:
25
26 UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Interface")
27 bool showinfo();
28 };
打开UE4,创建一个ACTOR类,在class settings里找到接口,搜索选择自己定义的接口。
左侧就会出现接口的showinfo函数,调用即可。