Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Problem with spawn object of Client

Discussion in 'Multiplayer' started by ApanasikOG, Jun 11, 2017.

  1. ApanasikOG

    ApanasikOG

    Joined:
    Sep 29, 2016
    Posts:
    2
    Hello everyone! I'm developing my Final Qualifying Work for a university. It's a mobile multiplayer-game which contains all data with help Google Services (save/load/refresh) and doing connections by UNet servers. And on my final step to complete project I've found very annoying for me a problem: we have 2 clients while one of them - it's the host-client. Player have class which contains array of prefabs. Every prefab of every player have specific values of variables: power, health points, speed, strong, cost etc. When we playing host-client spawn own prefabs without any problem: if own prefab have 20 strong points - in the game that prefab will be have the same value of strong (20 points). But if client want to spawn own prefab (for example, with 50 strong points) - server will spawn server's prefab (with 20 strong points). Generally: client can't to spawn own object with own values. What to do, guys? Until the 16th June I must to solve this problem.​

    What was I doing:
    • Was trying to get object by GetInstanceID(). I was getting this ID, client getting this ID too but as before I can not to create (to spawn) object of client;
    • I can't to spawn object which we got as parameter from signature of a method with attribute [Command] because in this case client will be throw NullReferenceException;
    • We can't to spawn object with [SyncVar] too;
    • If we change attribute of our CmdinstantiateObject() method from [Command] to [Server] than only server will can to spawn own prefabs;
    • Was trying to registrate prefabs in OnStartClient) on each client - without any result;
    Hopefully anybody can to help me!

    Code (CSharp):
    1.        
    2. [Command]
    3. private void CmdInstantiateObject(Vector3 pos, int _currentUnit, int _money)
    4. {
    5.      GameObject objectForInstantiate
    6.           = Instantiate(_units[_currentUnit], pos, Quaternion.Euler(90, 0, 0));    
    7.      NetworkServer.Spawn(objectForInstantiate);
    8. }
     
  2. ApanasikOG

    ApanasikOG

    Joined:
    Sep 29, 2016
    Posts:
    2
    Guys, anyone know how to help me?