Client-side smoothing - example script trouble!

Hi there,

I have an application set up where I can connect multiple instances over a local network. At the moment I am just moving a box, whilst I figuring out how to get client-side smoothing working.

I have the script from the Unity networking examples, which looks like it is working. The only trouble is that the boxes (that the client doesn’t own) are having their position set to 0,0,0 every frame/update/whatever.

The only time someone else’s box is in the correct place is when it is moving, and even then it flickers between that position and the world origin. The prefab I am spawning has a starting transform position of 0,0,0 and is placed in a specific location by the Network.Instantiate() function when the client connects.

I thought the problem could have something to do with these 2 lines:

if (stream.isWriting)
    {
        *Vector3 pos = transform.localPosition;*    // this one
        Quaternion rot = transform.localRotation;
        stream.Serialize(ref pos);
        stream.Serialize(ref rot);
    }
    // When receiving, buffer the information
    else
    {
        // Receive latest state information
        *Vector3 pos = Vector3.zero;*         // and this one
        Quaternion rot = Quaternion.identity;
        stream.Serialize(ref pos);
        stream.Serialize(ref rot);

but neither broadcasting the world position nor initialising the recieving vector differently made any difference, so the reason the box is being set to the origin isn’t that.

When I change the box prefab’s NetworkView component to Unreliable the box flickers regardless of user input.

In my mind I think that the client is, for some reason, resetting the prefab to its original transform position unless it gets sent where to put it.

I find this strange as without the smoothing script, my boxes do not flicker although they do have jerky movement because of lag.

Does anyone have any suggestions? Thanks,

Simon.

SOLVED!

Well, this was the most GODAWFUL, STUPID bug I have ever come across, and I’ve had a years’ worth of experience with UDK, which says a lot!

Deary me, where to start?

In order to see what was happening in the built exe file, I created a GUIText object to display debug strings. I added a Start() function to the NetworkInterpolateTransform script to find the object in the scene and save it in a variable.

void Start()
{
    debugText = (GUIText)GUIText.FindObjectOfType(typeof(GUIText));
    if (debugText != null)
        debugText.text = "Yay I have been found!";        
}

logical enough, right?

With the script like this, the boxes not belonging to the client would stay fixed at 0,0,0 and OnSerializeNetworkView would only have run the once.

BUT if you change void Start() to void Awake() , everything starts running dandy!

This smoothing took me all of 8 hours to implement, WAY more than it should have.

Does anyone have an explanation as to why assigning the debugText object in Awake() rather than Start() would make any difference?

Today was a long day ;_;

Simon!