PhotonNetwork.Destroy bug I am having + some questions

Options
cj31387
cj31387
I have my game set up that when my player hits another player, a blood effect prefab gets PhotonNetwork.Instantiated then another script is on the blood prefab to PhotonNetwork.Destroy(gameObject) it works most of time but it seems like all the players are trying to destroy it and if its not theirs it says this

[code2=csharp]Ev Destroy for viewId: 1017 sent by owner: True this client is owner: False
UnityEngine.Debug:Log(Object)
NetworkingPeer:OnEvent(EventData) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1554)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:76)[/code2]

Well eventually after playing a while sometimes the blood particles stay in the game and never get destroyed and I don't know exactly what is causing it, but it creates tons of fps drop and lag.

Here is the code for instantiate and destroying the blood particle.

[code2=csharp]if (hit.collider.tag == "Player")
{

PhotonNetwork.Instantiate("BloodSplat", hit.point, hit.transform.rotation, 0);
//print("Istantiated the blood");

//audio.pitch = Random.Range(SoundImpactPitch.x, SoundImpactPitch.y) * Time.timeScale;

SendLocalBloodHitSound();
}[/code2]

[code2=csharp]using UnityEngine;
using System.Collections;

public class DestroyBloodPrefab : Photon.MonoBehaviour {

public float destroyTime = 0;

// Use this for initialization
void Start () {
if (photonView.isMine == true)
{

}
else
{
enabled = false;
}

}

// Update is called once per frame
void Update () {
destroyTime += Time.deltaTime;
if (destroyTime >= 0.5)
{
PhotonNetwork.Destroy(gameObject);
}
}

void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
// We own this player: send the others our data
}
else
{
// Network player, receive data
}
}
}[/code2]



Also there is still a lot of unity pun networking I don't understand yet. What condition would I set up so that only the owner of that blood prefab attempts PhotonNetwork.Destroy on it?

Some things I would like to know.

In tutorials it seems like anything having to do with input should be wrapped with

[code2=csharp]if (photonView.isMine == true)
{

}
else
{
enabled = false;
}[/code2]

But is that all? Can someone explain why disabling a script if its not yours is necessary sometimes. And which cases you should not disable a script that is not yours. Because sometimes you get null refs when 2 players try to do something and their scripts are both active. But some scripts need to be active for all sometimes. Thanks in advance

Comments

  • Tobias
    Options
    Particles and effects which all clients can sufficiently simulate locally should never be synchronized with PhotonViews on them.
    If you have enough of them not only your frames will suffer but also connection quality.
    Keep in mind: To trigger some effects, you can simply couple them with some meaningful action like "i shot this and that" or "player X was hit and now bleeds". You don't need to send a lot of messages for particles if any client knows to spawn them on hit and remove them 2 sec after they spawned.

    > What condition would I set up so that only the owner of that blood prefab attempts PhotonNetwork.Destroy on it? [...] But is that all?
    Yes.
    And no.

    That solution disables a complete script. If the script only does things that should be done "only on local items" or "only on remote player's items", then it's good. Most scripts do more than just reading input and applying it in one way or another. In that case, it's not so easy to just disable a full script and hope it works fine.
  • cj31387
    Options
    The blood effects work a lot better now thanks!