Unreal Learning Notes 7—Blueprint Interface

I. Introduction

        The blueprint interface is an interface that can be implemented in a blueprint. It has its convenience and can easily call functions that implement the interface.

2. Realization

2.1. Create a blueprint interface

1) Multiple functions can be added.

2) Functions can only specify input and output parameters in the blueprint interface.

        Only input parameters can be used as events, as shown in Figure 2.1.1. Once you click "Convert function to event", it is no longer a function. Even if you delete the converted event in the "Event Chart", it will not work. When you turn back and right-click the "function with only input parameters", only the "implementation event" and other operations will be displayed, as shown in Figure 2.1.2:

Figure 2.1.1
Figure 2.1.2

Although functions with input and output also have the operation of "converting functions into events" as shown in Figure 2.1.1, the error as shown in Figure 2.1.3 will pop up after clicking on it.

Figure 2.1.3

2.2. Inherit the blueprint interface

1) Select "Class Settings" in the newly created Actor or other blueprint and select the interface created in 2.1 in Interface - "Implemented Interface"

Figure 2.2.1

2) After adding the interface, all functions in the interface will be automatically created and overloaded. You only need to add specific implementations to each overloaded function.

2.3. Use blueprint interface

1) Get all Actors that inherit the interface: Traverse all Actors with target interfaces, and then call the functions in the interface, as shown in Figure 2.3.1, so that all actors that inherit the interface will be executed.

Figure 2.3.1

2) Get all Actors: traverse all classes and then force the execution of the "new function" defined by the interface, as shown in Figure 2.3.2, here it is

Figure 2.3.2

It's a bit "weird". Unreal allows this operation. If the interface is implemented, the logic of the interface will be executed . If the interface is not implemented, it can be executed and finally printed.

3) Get all controls that inherit the interface

Figure 2.3.3

4) Get components by interface

Figure 2.3.4

3. Summary

3.1. The blueprint interface has some differences between input parameters and output parameters.

3.2. Some methods and differences in calling the blueprint interface.

Guess you like

Origin blog.csdn.net/zhangxiao13627093203/article/details/134693740