- Home /
RakNet RPC calls between C++ and Unity
Looking in the forum old topics seems to tell that Unity3D does the same as RakNet RPC3 without using AutoRPC nor RPC3.
Like other I'd like to transmit data between Unity and a server in C++ on Linux. There are many reasons for that, like performance, OS portability, memory usage, flexibility, reliability...
After receiving a RPC call in C++ from Unity, I have RPCParameters* rpcParms
but those are the compressed bitstream generated by Unity. Is there a C++ utility to decompress them?
Answer by Wernight · Mar 03, 2010 at 09:06 AM
By trial and error I found this:
In Unity (C#):
[RPC]
MyRPC
void MyRPC(int a, float f, string s)
{
// Dummy, only used in the C++
}
In C++:
static void MyRPC(RPCParameters* rpcParms) { size_t byteCount = (rpcParms->numberOfBitsOfData + (8-1)) / 8
RakNet::BitStream bits(rpcParms->input, byteCount, false);
bits.IgnoreBits(20); // Skip some unknown bit (2 and half bytes in fact)
int a;
bits.Read(a);
float f;
bits.Read(f);
char s[100];
StringCompressor* sc = StringCompressor::Instance();
sc->DecodeString(s, sizeof(s)/sizeof(char), &bits, 0);
}
This will read all the parameter send by a RPC call from Unity. The reverse also work: Making a RPC call from C++ to Unity.
Note: I didn't include all the RakNet elements. You'll have of course to initialize RakNet and process the messages in your main loop etc., just as RakNet says. A good starting point is the C++ master server for Unity source code.
Answer by kilkis · Jun 22, 2011 at 02:04 AM
For some reasons I must make my server in C++ and RakNet,so I do it like this in C++: RakNet::BitStream reply; NetworkID nid; nid.guid = peer->GetGuidFromSystemAddress(packet->systemAddress); peer->RPC( "testRPC",∈Bitstream, HIGHPRIORITY,RELIABLEORDERED,0,packet->systemAddress,false,0,nid, &reply);
but,unity3d tell me that "Internal RPC error. Network ID used for static RPC function, function incorrectly called.", and I can't find anything about it,so I hope anyone knows it to help me,thank you!
Your answer

Follow this Question
Related Questions
How can I get deep info on configuration of Unity networking? 0 Answers
OnSerializeNetworkView issus in my 2D game 3 Answers
Does Unity merge RPC calls into one packet per tick? 0 Answers
Unet Bufferd RPC 0 Answers