Is it possible to use IPC to create a connection between a c++ class(e.g. player controller) and a external process?

Hi Guys, I am a beginner here.
The picture shows my idea. I am using Carla to create a small dataset. Carla is a simulator with a client-server model. Its server-side is based on UE, and its client-side is a python script. Now I want to create a c++ class to do something with a Carla Town( for example toggle visibility of spawned actors in the Town). And the actors’ info will be from the Carla client-side( a python process). So I think, that I can use an IPC to connect the python process and C++ process to transfer info about the actors. is it possible for a UE c++ class?

Yes, an unreal actor is just a C++ class.
You can call some library to open up IPC (maybe a UDP socket) in the controller.
Inside the Tick() for the controller, you can service the IPC, say by calling recvfrom(). (especially if the socket is non-blocking).
You can then sendto() the socket on whatever port it’s bound to pass data to the controller.
If you want to use TCP or gRPC or some other mechanism, it’s the same general idea: make the controller set up whatever it needs to do to listen, and poll the RPC/IPC mechanism inside Tick().

That being said, if you want to use multiplayer, you’ll have to figure out whether you want to listen on the client, or on the server, and if multiple controllers listen on the server, they can’t all bind to the same port, for example. This is all standard IPC stuff.

The main two things that are important:

  • Unreal can call arbitrary C++ code, but you may need to wrap that code behind some library API, because including system headers directly inside Unreal dependent code doesn’t always work well
  • Tick() is a reasonable place to harvest whatever IPC messages come in. You should make that be asynchronous – either use non-blocking I/O, or spawn a separate thread to accept/read/decode messages, and put them in some kind of queue that the Tick() function dequeues from.
1 Like

That’s great. Thank you so much.:slight_smile: