Very Strange Error

Hi all, my first post so please be gentle :sweat_smile:

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?

No - this is the School of Hard Knocks, you’ll get no sympathy here :wink:

Just to be clear, is the code not working, or is it just that the asserts are annoying? You should report the asserts using the Report Bug app (in the same folder as the Unity app), but if your code isn’t working then we have a bit* more thinking to do.

*Edit: no pun intended.

Well the program wasn’t working, but I was unsure if it was my code given the strangeness of the errors. Turns out it was actually a problem with a prefab I was using, I guess Unity isn’t too elegant at handling that kind of thing yet (at least on windows). As it happens I now have a crippling problem stopping me from actually starting Unity up, but if it persists after a reinstall then I’ll post an update after work. =)

It might just be that the current project has been corrupted. If you hold down the alt key while launching Unity, you can start off with a new project. Worth trying, anyway, before you go to the trouble of reinstalling.