- Home /
Is this bad for the network?
Hello everyone!:)
So, I am currently developing my own online multiplayer shooter on Unity engine and am currently using Photon Networking as my server + networking of the game. Now, I have an enemy which loops playing an idle animation and if a player gets within 10 feet of him, I want him to play his walking animation but, of course, I want everyone to see his animation is now walking so I must sent it over the network. This is what I am doing for that:
if (Vector3.Distance(player.transform.position, this.transform.position) < 10) {
transform.LookAt(player.transform.position);
transform.position += transform.forward * 0.8f * Time.deltaTime;
//transform.Translate(0.8f * Vector3.forward * Time.deltaTime);
transform.GetComponent<PhotonView>().RPC("PlayWalkAnimation", PhotonTargets.All);
}
}
[RPC]
public void PlayWalkAnimation() {
animation.Play("walking_3");
}
This is all in the Update void and if someone is next to the enemy then it will constantly call "walking_3" animation with a RPC network call every Update void so would this be too intense for the Photon Network? And if so, how can I make this work but not so poorly coded to stress the network ?
Just a side note. The Update()
function is called as much as possible. I think you should at least place this in a FixedUpdate()
. This function is only called 60 times a second. I can unfortunately, not help you any further as I've never used the network. Please see Unitys video about it here: Update and Fixed update
Answer by fholm · Jun 16, 2014 at 08:31 AM
Yes this is very bad for the network.
It's not actually bad for the network. The amount of data sent would be off by a factor of hundreds when compared to video strea$$anonymous$$g and FTP. I'm going to have to -1 for simply being wrong.
Answer by Benproductions1 · Jun 16, 2014 at 10:19 AM
While not technically "bad", ie. it won't overload your network (or even come close), it's not even near optimal. Unless you're doing this thousands of times per second, you're not actually sending that much data. But note that it does stack up, and while "not bad for the network" will stay true, the CPU overhead of serializing, packaging, unpackaging, deserializing, reflecting and calling can definitely become a bottleneck.
You should only call animation.Play
once, meaning you should also only call your RPC
once.
Honestly, the CPU will never be bottlenecked on something like this, you will crash the network before you overload the CPU
Your answer
Follow this Question
Related Questions
Tying to parent objects in game with Photon.PUN OnPhotonSerializeView 0 Answers
Photon Network Problems 1 Answer
Photon wont sync for the masterclient. 1 Answer
Unity3D Photon movement synchronization 0 Answers
Multiple Cars not working 1 Answer