Ok so I’m making a multiplayer space shooting game, I’ve had some trouble reducing latency when my ships shoot proyectiles (I used Instancing and spawning on every shot), my next idea was using an object pooling aproach as I had before when protoyping the game on offline mode. I would have a weapon component on my player, a pool size parameter and on awake I would instance the bullets a disable them. I’m trying the same aproach on multiplayer, the thing is when I instantiate the bullet prefabs, prepare them on my local player and then proceed to synchronize them to my clones on the other clients I receive this message even though all bullets are instantiated and initializaed correctly. My player prefab has local authority and I tried giving local autority to the bullet prefab, didn’t work either. Don’t even know if the warning keeps me from doing what I intent, it just bothers me, like I’m doing something wrong, I’m new to networking.
Trying to send command for object without authority
The code for spawning the bullets in my weapon script
void Start()
{
InitSpawnPositions();
InitBullets();
SyncBullets();
}
private void InitBullets()
{
bullets = new Bullet[poolSize];
for (int i = 0; i < poolSize; i++)
{
bullets[i] = Instantiate(bullet, self.position, self.rotation).GetComponent<Bullet>();
bullets[i].Init(gameObject);
}
}
[Client]
private void SyncBullets() {
CmdSyncBullets(gameObject);
}
[Command]
private void CmdSyncBullets(GameObject parent) {
for (int i = 0; i < bullets.Length; i++)
{
NetworkServer.Spawn(bullets[i].gameObject);
RpcSyncBullet(bullets[i].gameObject, parent);
}
}
[ClientRpc]
private void RpcSyncBullet(GameObject bullet, GameObject parent) {
bullet.GetComponent<Bullet>().Init(parent);
}
My bullet Init Method
public override void Init(GameObject owner)
{
this.owner = owner.GetComponent<Weapon>();
this.self.parent = this.owner.Self;
this.available = true;
this.lifeCounter = 0f;
this.gameObject.SetActive(false);
}
I leave the complete files below.
Please help.
3904531–332521–BasicBlaster.cs (3.62 KB)
3904531–332524–BlasterBullet.cs (2.56 KB)