UE4 blueprint interface BluePrint Interface

BluePrint Interface

What is the blueprint interface?

A blueprint interface is a collection of one or more Functions. It has no implementation and can be added to other blueprints. Any blueprint that adds an interface is guaranteed to have these functions. In each blueprint class that adds a blueprint interface, Functional implementations can be added to it. Similar to the interface concept in programming. Allows objects of different types to access it through a common interface.

Why use blueprint interface?

In use, the Blueprint interface allows a common way to interact with all objects that have a Blueprint interface. This means that across different types of objects, they can have the same functionality. Cars and trees, for example, can be shot by weapons. So you can create a blueprint interface and call the corresponding function when the weapon shoots a car or a tree.

How to use blueprint interface?

[Make buttons to control animal calls] Press 2 keys, and puppies and calves will make different sounds.

1. Create a new Blueprint Interface.

2. Add a function to the newly created BluePrint Interface and click Add New.

Voice is called Function. Here we declare a Voice function, then write the implementation in the class to which the interface has been added, and then call this function elsewhere.

3. Create two new Actors, one is Dog and the other is Cow.

4. Open the newly created Dog class and add the blueprint interface created above in Class Setting.

5. Complete the implementation of Voice.

6. Perform the same operation on the Cow class and output MOUMOU in Print String.

7. We add this interface to the level blueprint and call this method.

8. Run, press 2, and get the sounds of Dog and Niu.

Summary: The blueprint interface first defines a function interface to tell others that this function exists and can be called, but each class can have different implementations.

The blueprint interface can perform one-to-many or even many-to-many broadcasting, with one call and multiple responses.

Supongo que te gusta

Origin blog.csdn.net/weixin_41363156/article/details/114356562
Recomendado
Clasificación