Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved RPCS and arrays

Discussion in 'Netcode for GameObjects' started by liambilly, Jul 14, 2023.

  1. liambilly

    liambilly

    Joined:
    May 13, 2022
    Posts:
    154
    1. i have an array in players script with diff positions to spawn a projectile, as follows
      Code (CSharp):
      1.  
      2. [ServerRpc(RequireOwnership = false)]
      3.     public void SecSpawnServerRpc(Vector3 hitpoint)
      4.     {
      5.         var spawnpoint = secondarySpawner[secCount.Value];
      6.         spawndSec = Instantiate(secondary, spawnpoint.position, spawnpoint.rotation);
      7.         //Instantiate(secondary, transform.position + Vector3.forward, transform.rotation);
      8.         var no = spawndSec.GetComponent<NetworkObject>();
      9.         no.Spawn();
      10.         spawnedammo.Add(spawndSec.transform);
      11.         SecSpawnClientRpc(hitpoint, no);
      12.  
      13.     }
      14.     [ClientRpc]
      15.     public void SecSpawnClientRpc(Vector3 hitpoint, NetworkObjectReference nor)
      16.     {
      17.         if (nor.TryGet(out NetworkObject netobj))
      18.         {
      19.             var spawndsec = netobj.GetComponent<Projectiles>();
      20.             spawndsec.SetIndexNOwner(this, spawnedammo.IndexOf(spawndsec.transform));
      21.             spawndsec.owner = this;
      22.             if (spawndsec.isHoming && hasLockedTrgt)
      23.                 spawndsec.lockedTrgt = lockedTrgt;
      24.             else
      25.                 spawndsec.hitpoint = hitpoint;
      26.  
      27.             StartCoroutine(spawndsec.Fired(lockedTrgt));
      28.             spawndsec.AddSpeed(pm.pi.speed - pm.pi.speed);
      29.  
      30.             print(netobj.transform);
      31.         }
      32.  
      33.     }
      34.  
    2. the problem is only the server is able to spawn , but for clients, they nothing is spawning
     
    Last edited: Jul 14, 2023