Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by shubhank008 · Jan 19, 2017 at 09:01 AM · unity 5networkingmultiplayernetworkmultiplayer-networking

UNET (Multiplayer) calling [command] function twice

I am playing around with UNET but stuck into this weird problem/scenario while testing on same machine (unityEditor and buildRun to create "2 players/instances"

The problem is weird interaction of [Command] attribute and void OnStartLocalPlayer() when hosting the game in Editor's instance and in standalonePlayer instance

  1. Basically, when I am host in editorInstance (host), the function associated with [Command] is triggered twice by the standaloneInstance (client)

  2. When I am hosting in standaloneInstance (host), the line which calls the function associated with [Command] throws warning "Trying to send command for object without authority." But the function works as expected

I am spawning a PlayerObject from my NetworkLobbyManager and then that PlayerObject spawns its own pieces (sub-objects) using NetworkServer.Spawn(playerUnit);

Any help would be appreciated :( I like learning by trial and error but since 3 days I have not progressed or understood whats going on.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Networking;
 
 public class playerManager : NetworkBehaviour
 {
     public int playerID;
     public GameController GC;
     public int playerUnitID;
     public bool localPlayer;
     public bool serverPlayer;
     public bool clientPlayer;
 
     // Use this for initialization
     void Start () {
         //Assign player unique ID as per order of joining
         if (!GC)
         {
             GC = GameObject.FindObjectOfType<GameController>();
             //playerID = this.GetComponent<NetworkIdentity>().connectionToClient.connectionId; connectionToClient is for serverOnly, connectionToServer is clientOnly
             playerID = (int)netId.Value;
             Debug.Log("(PM) Created GC in Start: " + playerID);
             //CmdCreatePlayerUnit(playerID);        //this gets called in OnStartLocalPlayer anyway(Trying to send command for object without authority)
         }
         localPlayer = isLocalPlayer;
         serverPlayer = isServer;
         clientPlayer = isClient;
 
         Debug.Log("Player: "+playerID+" isLocalPlayer: "+localPlayer+" and isServerPlayer: "+serverPlayer);
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 
     public override void OnStartLocalPlayer()
     {
         if (!GC)
         {
             GC = GameObject.FindObjectOfType<GameController>();
             //playerID = this.GetComponent<NetworkIdentity>().connectionToClient.connectionId; connectionToClient is for serverOnly, connectionToServer is clientOnly
             playerID = (int)netId.Value;
             Debug.Log("(PM) Created GC in OnStartLocalPlayer: " + playerID);
             CmdCreatePlayerUnit(playerID);
         }
         //Debug.Log("(PM) OnStartLocalPlayer: " + gameObject.name);
         Debug.Log("Player: " + playerID + " isLocalPlayer: " + localPlayer + " and isServerPlayer: " + serverPlayer);
     }
 
     [Command]
     void CmdCreatePlayerUnit(int playerID)
     {
         Debug.Log("Creating player unit with ID: " + playerID + " and isLocalPlayer: "+isLocalPlayer);
         GC.registerPlayerNetID(playerID);
         Debug.Log("(PM) Registered Players: " + GC.playerNetIDs.Count);
         for (int i = 0; i < GC.playerNetIDs.Count; i++)
         {
             //Debug.Log(GC.playerNetIDs[i]);
             if(GC.playerNetIDs[i]==playerID)
             {
                 playerUnitID = i;
                 Debug.Log(playerID+" player's unitID is "+i);
             }
         }
         GameObject prefab = GC.players[playerUnitID];
         GameObject playerUnit = (GameObject)Instantiate(prefab, prefab.transform.position, prefab.transform.rotation);
         NetworkServer.Spawn(playerUnit);
 
         //Update the same in GC
         GC.registerPlayer1(playerUnit,(int)playerUnitID);
     }
 
 
 
      
 
 
 }
 

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

182 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

local scale network 0 Answers

[UNet] Network Animator transition stutters 0 Answers

How do I sync Rigidbody2D over the network? 0 Answers

How to send Kinect skeleton data through Unity networks (multiplayer) 0 Answers

[UNET 5.2] Multiple local authority for 1 object? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges