- Home /
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
Answer by Jeston 1 · Oct 06, 2010 at 07:20 PM
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..
Answer by Dreamora · Oct 04, 2010 at 07:39 PM
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.
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 :(
Your answer
Follow this Question
Related Questions
Multiplayer FPS Fail 4 Answers
Network? controles backwards? 1 Answer
A name For the Character Please Help 3 Answers
Bullets going wrong direction 1 Answer
Network fps swap cameras 1 Answer