every Network Instantiated Object is created Twice

Hi,
I got a small problem and I'm not sure from where it is coming.
I use a very Simple Network script to create and Join a Room.
Network Script


It creates a button to Create a Room, if there is a Room join it and Create the Player.
After creating the Player i got a WeaponManager.cs wich calls a Method in Start();, this Mehtod, creates the GunObject,MuzzleFlash and calls my ObjectPool script wich create Hiteffects,Projectiles for Bazooka ,..,.. most of the Object get Parent to the Player. My Problem now is, if one Player create/Join a Room everything is working good, but if the second Player is joind every Object is created again.


thats the Problem

Thats the part where every Object gets created.

Comments

  • [SerializeField] GameObject gbj;
    GameObject newCube;

    void Update()
    {

    if (photonView.isMine)
    {
    if (Input.GetKeyDown(KeyCode.K))
    {
    print("1");
    Create();
    }
    }
    }

    void Create()
    {
    print("2");
    newCube = PhotonNetwork.Instantiate(gbj.name, this.transform.position+new Vector3(0,4,0), Quaternion.identity, 0);

    photonView.RPC("ChildObj", PhotonTargets.All, newCube.GetPhotonView().viewID);
    }
    [PunRPC]
    void ChildObj(int id)
    {
    PhotonView[] cube = FindObjectsOfType();
    foreach(PhotonView p in cube)
    {
    if(p.viewID == id)
    {
    p.transform.SetParent(this.transform);
    }
    }
    }

    I think here is the Solution. I got 2objects because I send a RPC with
    PhotonNetwork.Instantiate to all.And the Hierarchy is messed up because I cant simply send a RPC with child one Object to another...
    i have to u search for the PhotonView id. This script work fine. I will test it and Edit this post if it works.
Sign In or Register to comment.