English | 简体中文
TurboLink is an unreal engine plugin that enables Google gRPC to work with Unreal Engine using C++ or Blueprint. It is compatible with UE 4.27 and 5.
oneof
field and self-nesting struct.
Two example projects can be downloaded, simple.demo.zip and full.demo.zip
It is recommended that first download example projects and run them to understand how the plugin works. All demo projects include UE projects and server projects that can be run directly.
TurboLink.example/Server
, and run go mod tidy
to update all module needed.go run main.go
localhost:5050
. Do not use 127.0.0.1:5050
because the certificate file in the sample project does not include this domain
If you do not have a golang runtime environment, you can connect the client to the server I provided (grpc.thecodeway.com). I will try to keep this server running.
Source/ThirdParty
.Plugins/TurboLink
folder under your project folder, then copy this repo into it.Open the project setting window (TurboLink Grpc/Services Config) to set the server endpoint to different gRPC services.
For services that do not have an endpoint set, turbolink will use the default endpoint to connect.
Turbolink support server-side tls connection type. If you want to enable this function, you need to set the server certificate file(PEM format) in the settings windows (TurboLink Grpc/Services Config). Because UE's setting window only supports single-line text, you need to replace the newline character in the certificate file with \n
.
For example, a simple gRPC service hello.proto
is as follows:
syntax = "proto3";
package Greeter;
option go_package = "./Greeter";
message HelloRequest {
string name = 1;
}
message HelloResponse {
string reply_message = 1;
}
service GreeterService {
rpc Hello (HelloRequest) returns (HelloResponse);
}
To use this service, in addition to using protoc
to generate *.pb.cc
and *.grpc.pb.cc
files, you also need to generate the code files required by turbolink.
There are 2 options to do so:
Follow this -
Click on Run Workflow
-> Run Workflow
. This will build all proto files in the .github/protos
directory.
Then at the end of the build - at the bottom of the summary page you will see the "Generated C++ Code" download link under Artifacts section.
To use your own .proto - you can clone/fork this repo and add your proto files in the .github/protos
directory.
In the tools
directory of the plugin, there is a batch file called generate_code.cmd
that is used to generate all the gRPC code files. Before using it, make sure you have installed the plugin into your project and all third-party library files are installed. The command line is:
generate_code.cmd <proto_file> <output_path>
In the proto file above, Use the following steps to generate code files:
generate_code.cmd hello.proto .\output_path
Private
and Public
from output_path
to YourProject/Plugins/TurboLink/Source/TurboLinkGrpc
This batch file generates code through a protoc plugin named protoc-gen-turbolink
, the code of this plugin can be found here. Do not put the project in the path containing spaces to avoid errors in execution.
If your project contains multiple proto files, and there are dependencies between files, then you should have a root directory to save these files, and then use this directory as the current working path to run generate_code.cmd
Use the following c++ code to link to the gRPC services.
UTurboLinkGrpcManager* TurboLinkManager = UTurboLinkGrpcUtilities::GetTurboLinkGrpcManager();
UGreeterService* GreeterService = Cast<UGreeterService>(TurboLinkManager->MakeService("GreeterService"));
GreeterService->Connect();
The above functions can be called directly in the blueprint.
There are several different ways of calling gRPC methods.
First, create the client object, and set the delegate function.
GreeterServiceClient = GreeterService->MakeClient();
GreeterServiceClient->OnHelloResponse.AddUniqueDynamic(this, &UTurboLinkDemoCppTest::OnHelloResponse);
Then create a context object and call the gRPC method.
FGrpcContextHandle CtxHello = GreeterServiceClient->InitHello();
FGrpcGreeterHelloRequest HelloRequest;
HelloRequest.Name = TEXT("Neo");
GreeterServiceClient->Hello(CtxHello, HelloRequest);
The above functions can be called directly in the blueprint.
If the gRPC call is a one-off, you can use a lambda function as a callback after the service is connected.
FGrpcGreeterHelloRequest HelloRequest;
HelloRequest.Name = TEXT("Neo");
GreeterService->CallHello(HelloRequest,
[this](const FGrpcResult& Result, const FGrpcGreeterHelloResponse& Response)
{
if (Result.Code == EGrpcResultCode::Ok)
{
//Do something
}
}
);
It should be noted that if it is a function of client stream type, lambda callback cannot be used.
In the blueprint, if you need to quickly test some gRPC functions, or use some one-off functions, you can use an asynchronous blueprint node, which can automatically complete the service link and callback processing.
Currently, the async node cannot support gRPC functions of client stream and server stream types.
In some cases, we need to convert protobuf messages and json strings to each other. Through the turbolink, this conversion can also be operated in the blueprint
The result is {"name" : "neo"}
One of the design purposes of TurboLink is to be able to use the gRPC directly in the blueprint, so some proto3
features cannot be implemented in TurboLink yet.
optional
field. And I have no plan to support functions like 'has_xxx' or 'clean_xxx' in the blueprint, which will greatly increase the complexity of the generated code.any
message type cannot be used in TurboLink either.Turbolink is a completely free and open source project. I maintain it in my own free time. If you get help from it, you can consider buying me a cup of coffee. Thank you!