1

Received RPC "RPCname" for viewID 2010 but this PhotonView does not exist! View was/is ours. Remote called. By: #01 'name'

using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{
    public PhotonView PV;
    int dir;

    void Awake()
    {
        PV = GetComponent<PhotonView>();
    }
    void Start() => Destroy(gameObject, 10f);


    void OnTriggerEnter2D(Collider2D col) // col을 RPC의 매개변수로 넘겨줄 수 없다
    {
        if (col.tag == "Border") PV.RPC("DestroyRPC", RpcTarget.AllBuffered);
        if (!PV.IsMine && col.tag == "Player" && col.GetComponent<PhotonView>().IsMine) // 느린쪽에 맞춰서 Hit판정
        {
            col.GetComponent<Player>().Hit();
            PV.RPC("DestroyRPC", RpcTarget.AllBuffered);
        }
    }


    [PunRPC]
    void DirRPC(int dir) => this.dir = dir;

    [PunRPC]
    void DestroyRPC()
    {

        Destroy(gameObject);
    }
}

I'm making a two-player shooter game, and bullets disappear when they hit a wall, but leave a warning message like that.

I asked chatGPT, so he said like this, but It not worked

        if (PV != null && PV.IsMine)
이관우
  • 3
  • 3

1 Answers1

0

It seems like you've completely messing up the workflow of a networked object. Please read the Photon Engine's manual on how to instantiate and delete networked entities. Besides that, it's not a good practice to make your bullets replicated in this way since you'll get all sorts of logic controversy for different players because of a floating point precision and network snapshot delay. It would be much better to have a network entity of a weapon that sends information aboul all bullets shot to other players from server.

Xander
  • 378
  • 1
  • 6
  • Thank you for Answer! But, I can't find another solution. How can I instantiate bullet better way? – 이관우 Jul 19 '23 at 10:54
  • You don't. Instantiate a weapon, let server to handle the shoot command from the client and calculate the bullet locally, then transmit only the minimal data for clients to draw the bullet effect. – Xander Jul 19 '23 at 11:57
  • Is it more efficient to create a prefabpool? – 이관우 Jul 22 '23 at 13:33
  • Yes, of course. Pooling is always more efficient since you're not creating objects on demand and only creating them once, maybe eventually expanding the pool if it is depleted. – Xander Jul 24 '23 at 10:38