Categories: CodingMarketUE

Blueprint Enchant tutorial

Table of Contents

Language: 中文 | >English<

Introduction

This library currently includes over 60 new blueprint nodes and is continuously being updated.

Plugin Modules

The plugin can be broadly divided into the following modules:

  • Network Module - Supports TCP/UDP Socket for sending and receiving data, defaulting to non-blocking mode.
  • Texture Module - Provides operations on Texture2D.
  • Byte Module - Allows manipulation of the actual memory address of blueprint variables.
  • Array Module - Adds blueprint nodes for array operations not well supported by default, such as wildcard sorting, deduplication, simulation of intersections, unions, differences, averaging, and weighted random selection.
  • Other Modules - Includes practical functions such as modifying named properties via strings (Struct.PropertyA.Property.Float), and other operations like random string generation, screenshot, etc.

Network Module

In Unreal Engine, I encapsulated FSocket to simplify its use. By using the BlueprintEnchantNetworkHandler class, you can quickly set up a socket.

For instance, setting up a TCP protocol involves the following nodes:

  • Create Socket Handler - The base for creating a Socket variable, allowing selection between TCP/UDP protocols, and whether it's server or client side, returning a created wrapper.
  • Bind - The Bind function is a member of Handler, so you need to set the returned handler as a variable and use it to call the Bind function, entering your local IP and port.
  • Set Receive Buffer & Set Send Buffer - These functions are used to configure the size of the data send and receive buffers, defaulting to 1024. Generally, no modification is needed unless specifically required.
  • Listen - This function is only for servers. If your Handler is a Server type, you need to use this function to listen for client connection requests, with parameters for the maximum number of connections.
  • Connect - Client-specific, if your Handler is a Client type, you need to use this function to connect to the server's bound IP.
  • Bind Event to On Accept - This server-specific delegate needs to be bound after Listen. When a client requests a connection, the Handler automatically handles acceptance and calls this delegate, returning a server Socket instance for communication with the client.
  • Bind Event to On Receive Data - This delegate triggers when the Socket receives a message, returning a byte array. You can use the BytesToString function to quickly convert it to a string, or adjust according to your additional needs. For a TCP Server, this delegate needs to be bound to the server Socket communicating with the client, not the initial Socket.
  • Send Data & Send String - Sends a string of data to the target.
  • Close - Closes this Socket.

    Here is a complete example for both a TCP server and a TCP client.
    Server

    Client

For a UDP protocol, the setup is much simpler since UDP does not require a connection between endpoints, but sends packets directly to the target IP.

  • Bind - First, bind an IP and port.
  • Send Data To & Send String To - These nodes are only for UDP, do not confuse them with TCP's Send Data & Send String, just input the IP and port to send.
  • Bind Event to On Receive Data From - Triggers when the bound IP receives a message, returning an IP and port.
  • Close - Releases the socket.

    Below is a complete UDP example.

Other features:

  • Tick In Editor - Enables network communication within the editor, suitable for editor development work.
  • Get Address - Retrieves the IP address of the target Handler.
  • Bind Event to On Connection State Changed - This delegate is called when the Handler's state changes.

Texture Module

Most functions in the texture module operate in BGR8 format. For functions that mandatorily require input channels like R, G, B, A, the Texture2D is first converted to BGRA8 before execution.

  • Get Texture Channel - Retrieves a specific channel from a Texture2D, creates a new Texture2D with only that channel, and returns it in Gray8 format.
  • Get Texture Color - Retrieves the color value at a specific position in a Texture2D, returning a Color type.
  • Set Texture Channel Value - Modifies a specific channel of a Texture2D, setting the entire channel to a single value.
  • Create Texture From Pixels - Takes an array of colors (from left to right, top to bottom) and the pixel dimensions of the image, returning a constructed Texture2D.
  • Swap Texture Channel - Swaps two channels in a Texture2D and returns a new Texture2D.
  • Get Texture Gray - Returns a new Texture2D representing the grayscale image of the input Texture2D. If UseAverage is checked, the grayscale is calculated by averaging; otherwise, it is calculated in a way that is sensitive to human eyes.
  • Get Texture Colors - Returns an array of colors from left to right, top to bottom.
  • Get Cursor Pos Color - Returns the color value at the current cursor position (only applicable on Windows platform).
  • Get Texture Average Color - Calculates the average color of all pixels in a Texture2D.
  • Get Viewport Pixels - Retrieves an array of pixel colors from the current runtime viewport.
  • Create Render Target 2D From Texture - Takes a Texture2D and returns a RenderTarget2D.

Byte Module

This module provides functionality to manipulate the actual memory address of blueprint variables, allowing users to directly modify data in memory. RefParam supports wildcard input.

  • Set Param Memory Bytes - Sets the memory bytes of a specified parameter.

    • Ref Param - The reference of the parameter to operate on.
    • Bytes Array - The byte array used to set values in memory.
  • Set Param Memory Index Byte - Sets a byte at a specific index in the memory of a specified parameter.

    • Ref Param - The reference of the parameter to operate on.
    • Index - The index position of the byte.
    • Byte - The byte value to set.
  • Get Param Memory Bytes - Retrieves the memory bytes of a specified parameter.

    • Ref Param - The reference of the parameter to operate on.
    • Return Value - The returned byte array.
  • Get Param Memory Index Byte - Retrieves a byte at a specific index in the memory of a specified parameter.

    • Ref Param - The reference of the parameter to operate on.
    • Index - The index position of the byte.
    • Byte - The returned byte value.
  • Bytes to String - Converts a byte array into a string.

    • Bytes - The input byte array.
    • Return Value - The converted string.
  • String to Bytes - Converts a string into a byte array.

    • String - The input string.
    • Bytes - The converted byte array.

Array Module

This module enhances support for array operations in blueprints.

  • Avg - Calculates the average value of all elements in an array.

    • Input Array - The input array.
    • Average - The calculated average value.
  • Dedupe - Removes duplicate elements from an array.

    • Input Array - The input array.
    • Output Array - The deduplicated array.
  • Pop - Pops the last element from an array.

    • Input Array - The input array.
    • Element - The popped element.
  • Push - Adds an element to the end of an array.

    • Input Array - The input array.
    • Element - The element to add.
  • Difference - Returns the difference set of two arrays.

    • Array A - The first array.
    • Array B - The second array.
    • Difference Array - The array of differences.
  • Intersection - Returns the intersection of two arrays.

    • Array A - The first array.
    • Array B - The second array.
    • Intersection Array - The intersection array.
  • NextPermutation - Generates the next permutation of an array.

    • Input Array - The input array.
    • Next Array - The array of the next permutation.
  • PrevPermutation - Generates the previous permutation of an array.

    • Input Array - The input array.
    • Previous Array - The array of the previous permutation.
  • Sort - Sorts an array.

    • Input Array - The input array.
    • Sort Order - The order to sort in (ascending or descending).
    • Sorted Array - The sorted array.
  • Random By Weight - Randomly selects an element from an array based on weights.

    • Input Array - The input array.
    • Weights - The array of weights corresponding to the elements.
    • Selected Element - The randomly selected element.
  • Union - Returns the union of two arrays.

    • Array A - The first array.
    • Array B - The second array.
    • Union Array - The union array.

File Operations Module

This module provides a series of nodes for handling files and folders in blueprints, making file management more direct and convenient. Here are the main nodes of this module:

  • Open Files - Opens a file selector for multiple files.

    • Default Path - The default path.
    • Selector Name - The name of the selector.
    • Filter - The file filter, e.g., "*.txt".
    • Return Value - The array of file paths chosen by the user.
  • Save String to File - Saves a string to a file.

    • Path - The file path.
    • String - The string to save.
  • Save Bytes to File - Saves byte data to a file.

    • Path - The file path.
    • Bytes - The byte data to save.
  • Open File - Opens a file selector for a single file.

    • Default Path - The default path.
    • Selector Name - The name of the selector.
    • Filter - The file filter, e.g., "*.jpg".
    • Return Value - The file path chosen by the user.
  • Open Folder - Opens a folder selector.

    • Default Path - The default path.
    • Selector Name - The name of the selector.
    • Return Value - The folder path chosen by the user.
  • Load Bytes from File - Loads byte data from a file.

    • Path - The file path.
    • Bytes - The loaded byte data.
  • Load String from File - Loads a string from a file.

    • Path - The file path.
    • String - The loaded string.

Other Modules

This module includes various utility nodes for performing miscellaneous tasks such as manipulating properties in structures, taking screenshots, and generating strings.

  • Set Struct Property - Sets the value of a property within a structure.

    • Struct - The instance of the structure.
    • Property Name - The name of the property, which can be a nested property path.
    • Value - The value to set.
  • Get Struct Property - Retrieves the value of a property within a structure.

    • Struct - The instance of the structure.
    • Property Name - The name of the property, which can be a nested property path.
    • Return Value - The retrieved property value.
  • Screen Shot - Captures and saves a screenshot.

    • Path - The path where the screenshot is saved.
  • Generate Random String from Dict - Generates a random string based on a dictionary of possible characters and their corresponding weights.

    • Dict - The dictionary containing possible characters and their weights.
    • Length - The length of the string to generate.
    • Return Value - The generated random string.
  • Generate Random String - Generates a random string.

    • Length - The length of the string.
    • Match Symbol - Whether to match a specific character set.
    • Return Value - The generated random string.

Mathematics Module

Continuously being updated...

  • Even - Determines if a number is even.

    • Input - The integer input.
    • Return Value - Returns true if the input is even, otherwise false.
  • Odd - Determines if a number is odd.

    • Input - The integer input.
    • Return Value - Returns true if the input is odd, otherwise false.
  • Get Angle Between Two Vectors (Radians) - Calculates the angle between two vectors in radians.

    • Vector A - The first vector.
    • Vector B - The second vector.
    • Return Value - The angle between the two vectors, in radians.
  • Get Angle Between Two Vectors (Degrees) - Calculates the angle between two vectors in degrees.

    • Vector A - The first vector.
    • Vector B - The second vector.
    • Return Value - The angle between the two vectors, in degrees.
同步Sch

Share
Published by
同步Sch