x


RPC causing chugs / performance

To those that know unity far more than me :)

I have a weird issue in a networked fps... Nothing particularly fancy is happening. I have a gunManager with its own NetworkView (state sync off) attached to a node called 'Weapons' which is some descendant in my player object hiearchy: which also has NetworkView w/ synchronized compressed data.

The GunManager is straight foward, it checks to see if the player has fired then RPC's when the shot is made with RPCMode.Others so that they can display the bullet/rocket/etc....

if (!LocalPlayer)
{ return; }

if (Input.GetButtonDown("Fire1"))
{
    //... gets info on camera 
   float distance = SelectedGun.Range;
   bool hit = Physics.Raycast(transform.position, worldDirection, out info, distance);

   if (hit && info.collider.gameObject.tag == "Player")
   {
       //calculates local damage, updates local score, etc...
    }

    networkView.RPC("FiredOneShot", RPCMode.Others, transform.position, worldDirection, info.normal, info.distance, SelectedGun.GunID);
    FiredOneShot(transform.position, worldDirection, info.normal, info.distance, SelectedGun.GunID);
   //...
}



    [RPC]
    public void FiredOneShot(Vector3 origin, Vector3 direction, Vector3 normal, float distance, int gunID)
    {
        Debug.Log("Player Fired: ");
        GunData.GunType type = GameData.Instance.GunData[gunID].Type;
        if (type == GunData.GunType.Rail)
        {
            if (distance < 5)
            {
                distance = 300;
            }

            Quaternion q = Quaternion.FromToRotation(new Vector3(0, 1, 0), direction);
            Transform t = (Transform)Instantiate(LazerPrefab, origin, q);
            t.localScale = new Vector3(0.2f, distance, 0.2f);
        }
    }

Given this, my lazerprefab is just a cylinder, but for some reason anytime a player who isn't the server 'fires', they have a local chug. But the server does not experience this. In fact, if the server fires alot everyone in the game chugs. The 'chug' is like a 5-10 FRAME lockup(drop) which is very disorienting. I am pretty sure this is the standard way of architecting networking for a gunshot. At first I thought it was the local Instantiate in the Rpc: FiredOneShot, but if I completely comment this function out I still notice the chugging. Has anyone else come across this or have suggestions to try out ?

Appreciate the advice, ~J

more ▼

asked Oct 04 '10 at 07:01 PM

Jeston 1 gravatar image

Jeston 1
129 8 9 16

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

It turns out that when I upgraded to Unity 3.0 this problem has completely gone away, so for those experience issues with your networking the older unity did a very bad job with state synchronizing that must have been fixed in unity 3.0, I didn't change any of my scripts and now its running smooth as butter...

strange..

more ▼

answered Oct 06 '10 at 07:20 PM

Jeston 1 gravatar image

Jeston 1
129 8 9 16

(comments are locked)
10|3000 characters needed characters left

your code is missing likely the most important check before it fires at all: "is time since last fire > firedelay" (and is firedelay reasonably large for network usage at all).

without that you basically flod the network which means that it will die down rather fast.

more ▼

answered Oct 04 '10 at 07:39 PM

Dreamora gravatar image

Dreamora
3.3k 1 4 25

yeah I make that check I just didn't post everything I felt was just related to the communication layer as opposed to any real local logic... The chug occurs whenever ANY RPC function is called it seems, when I do an ammo pickup, a gun firing, a respawn, a player leaving the server... and I am following all the practices of the other tutorials :(

Oct 04 '10 at 09:51 PM Jeston 1
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1198
x733
x21

asked: Oct 04 '10 at 07:01 PM

Seen: 786 times

Last Updated: Oct 04 '10 at 07:01 PM