Hi all, my first post so please be gentle
I’m laying the groundwork for a multiplayer game in Unity at the moment using .net sockets. So far I’ve just got clients sending their position every so often to a server. I just added in code so that these position updates also include the direction that the player is facing, and I’m getting some really weird errors on the host side. This is what I get in the console window:
Object::IDToPointer (headID) != NULL
IDToPointer (instanceID) != NULL
ms_IDToPointer.find (GetInstanceID()) != ms_IDToPointer.end ()
And These errors apparently occur respectively in:
Assert in file: …..\Runtime\Serialize\PersistenManager.cpp at line: 706
Assert in file: …..\Runtime\BaseClasses\BaseObject.cpp at line: 373
Assert in file: …..\Runtime\BaseClasses\BaseObject.cpp at line: 191
To clear something up, currently the host doesn’t relay the client movement updates to the other clients yet, it just moves the players around so I can see that it’s working…
At a guess I’d say this is a memory management issue on my end or some such? The code that changed to add this in is as follows:
// Host.cs
case MessageType.MOVEMENT_REQUEST:
{
int readIndex = 1;
float x = BitConverter.ToSingle( msg, readIndex );
readIndex += sizeof( float );
float y = BitConverter.ToSingle( msg, readIndex );
readIndex += sizeof( float );
float z = BitConverter.ToSingle( msg, readIndex );
readIndex += sizeof( float );
m_players[i].transform.position = new Vector3( x, y, z );
// New Code
x = BitConverter.ToSingle( msg, readIndex );
readIndex += sizeof( float );
y = BitConverter.ToSingle( msg, readIndex );
readIndex += sizeof( float );
z = BitConverter.ToSingle( msg, readIndex );
readIndex += sizeof( float );
float w = BitConverter.ToSingle( msg, readIndex );
readIndex += sizeof( float );
m_players[i].transform.rotation = new Quaternion( x, y, z, w );
}
break;
// Client.cs
TimeSpan sinceLastRequest = DateTime.Now - m_lastMovementRequest;
if( sinceLastRequest.TotalMilliseconds >= MOVEMENT_REQUEST_FREQUENCY )
{
m_lastMovementRequest = DateTime.Now;
byte[] bvMR = new byte[ Common.MESSAGE_LENGTHS[ (int)MessageType.MOVEMENT_REQUEST ] ];
bvMR[0] = (byte)MessageType.MOVEMENT_REQUEST;
int writeIndex = 1;
Array.Copy( BitConverter.GetBytes( gameObject.transform.position.x ), 0, bvMR, writeIndex, sizeof( float ) );
writeIndex += sizeof( float );
Array.Copy( BitConverter.GetBytes( gameObject.transform.position.y ), 0, bvMR, writeIndex, sizeof( float ) );
writeIndex += sizeof( float );
Array.Copy( BitConverter.GetBytes( gameObject.transform.position.z ), 0, bvMR, writeIndex, sizeof( float ) );
writeIndex += sizeof( float );
// New code
Array.Copy( BitConverter.GetBytes( gameObject.transform.rotation.x ), 0, bvMR, writeIndex, sizeof( float ) );
writeIndex += sizeof( float );
Array.Copy( BitConverter.GetBytes( gameObject.transform.rotation.y ), 0, bvMR, writeIndex, sizeof( float ) );
writeIndex += sizeof( float );
Array.Copy( BitConverter.GetBytes( gameObject.transform.rotation.z ), 0, bvMR, writeIndex, sizeof( float ) );
writeIndex += sizeof( float );
Array.Copy( BitConverter.GetBytes( gameObject.transform.rotation.w ), 0, bvMR, writeIndex, sizeof( float ) );
writeIndex += sizeof( float );
Anything in there that likely caused it?