Convert Primitive Types to and from Bytes
Supported Types and Nodes
Basic types provide two-way ToBytes and FromBytes conversion:
| Type | To bytes | Restore from bytes |
|---|---|---|
| int32 | IntToBytes | BytesToInt |
| int64 | Int64ToBytes | BytesToInt64 |
| float | FloatToBytes | BytesToFloat |
| double | DoubleToBytes | BytesToDouble |
| bool | BoolToBytes | BytesToBool |
| FString | StringToBytes | BytesToString |
All nodes are BlueprintPure and can be used directly as pure Blueprint functions without execution pins.
Use these nodes for custom protocols, lightweight storage, and binary communication. The C++ snippet below illustrates how the conversion works.
Blueprint Conversion Example
The first graph prints numbers, a Boolean, and a string after converting each value to bytes and back with its matching node.
The second graph converts a vector, a color, and a constraint struct to bytes and back, then reads a component or field.
The third graph prints byte array lengths and JSON text for structs. The two outputs serve different purposes.
Memory Layout, Byte Order, and UTF-8
This C++ example shows how to convert a primitive value:
// 以 int32 为例,直接内存拷贝void ByteConverter::IntToBytes(int32 Value, TArray<uint8>& OutBytes){ OutBytes.SetNumUninitialized(sizeof(int32)); FMemory::Memcpy(OutBytes.GetData(), &Value, sizeof(int32));}The example uses FMemory::Memcpy to copy a primitive value’s memory representation. String conversion uses UTF-8 and handles the null terminator for use across platforms.
UTF-8 defines the text encoding. Both endpoints still need to agree on the length, whether it includes the terminator and how to represent empty strings. The receiver cannot assume that an arbitrary byte array contains a readable terminator. The int32 example uses the host’s representation and specifies no byte order for cross-platform use.


