Blueprint Basics (5) - Functions

Briefly
In UE4, functions are actually nodes, which encapsulate modules that complete certain functions to make the program structure clearer and easier to read. A function has a unique entry and exit, but it can have multiple incoming and outgoing values.
For example, there is currently a function that needs to be implemented, to find the number of all daffodils between two numbers, save it to Array and return.
Note: Daffodil refers to a 3-digit number, and the sum of the three powers of the digits on each digit is equal to itself, (such as 1*1*1+3*3*3+5*5*5=153 ) to
create a function
Go to the My Blueprint panel, in the Functions section, click "+" to create a new function, name it DaffodilFunc, click Compile

Select the function DaffodilFunc and go to the Details panel. The Details panel mainly has three parts: property setting, input and output.

Property settings and their descriptions

Attributes

describe

Description

Description and description of the function

Category

the function class

Keywords

Keyword by which functions can be searched

Compact Node Title

The function name, which is plotted on the function node

Pure

whether the function is pure

Access Specifier

(access modifier)

 

Public (public) any external object can access the function. This is the default setting

Protected Only the current Blueprint and any Blueprints that inherit the current Blueprint can access this function.

Private calls the function from the current blueprint

Call In Editor

 

Const

This function cannot modify any members in the object, only read, not write


The properties are set as follows

Set input and output
Go to the Details panel, click the "+" behind Inputs, add an input parameter, name it StartValue, set it to integer type, the default value is 0, do not use reference to pass

We need to pass a value range, so we also need to add an input parameter named EndValue, also set to integer type, the default value is 999, do not use reference to pass, the result is as follows

With the incoming parameters, we also need to return the value, click the "+" behind Outputs, add a return value and name it ReturnValue, because we don't know how many daffodils we can find, so we can't set one or more return values. , we can return a container Array. The result is as follows
Now the function DaffodilFunc just completes the setting of input parameters and return value, there is no specific implementation, it should look like this

If you want to implement this function, you only need to add a functional algorithm in the middle. Let's start to implement it.

Use the function
to switch to the event icon, search for and execute the DaffodilFunc function, traverse the returned Array value, and print the number of daffodils

result output

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325777888&siteId=291194637