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 /
avatar image
0
Question by Orami · Jan 26, 2016 at 08:17 PM · networkingunity5noobcommand

Trouble using [Command] in a login script for a server.

I have been writing some code to allow players to login or create new accounts for my game. So as always I make some framework and keep checking to make sure it is working correctly. I have run into a snag where a non-local player can not use the commands in this script and it gives the error "Trying to send command for object without authority UnityEngine.Networking.NetworkBehaviour:SendCommandInternal(NetworkWriter, Int32, String)"

Perhaps I am misunderstanding the [Command] deal I thought that was code that was only executed on the server and I could send one parameter? Where code that is executed on the client only is [Client] or [ClientCallback]? Why does it not let me send the login information and gives me an error instead?

I have network identity on the object and set as local player auth

the login script just has a couple InputFields for player input and the rest was just checking to make sure I could decode the name / password.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Networking;
 using UnityEngine.UI;
 
 public class Login : NetworkBehaviour
 {
     public InputField PasswordField;
     public InputField UsernameField;
     public string username;
     public string password;
     public string LoginString;
     public string usernamedec;
     public string passworddec;
     // Use this for initialization
     void Start ()
     {
         
     }
     
     // Update is called once per frame
     void Update ()
     {
         password = PasswordField.text;
         username = UsernameField.text;
         LoginString = username + "@" + password;
         //usernamedec = LoginString.Remove(LoginString.IndexOf('@'));
         //passworddec = LoginString.Substring(LoginString.IndexOf('@')+1);
     }
 
     public void tryLogin()
     {
         if (username == "" || password == "") return;   //no null fields.
         CmdLoginCharacter(LoginString);
     }
     public void tryCreate()
     {
         if (username == "" || password == "") return;   //no null fields.
         CmdCreateNewCharacter(LoginString);
     }
 
     [Command]
     void CmdCreateNewCharacter(string loginString)
     {
         Debug.Log("Creating...");
         Debug.Log("Name: " + loginString.Remove(loginString.IndexOf('@')));
         Debug.Log("Password: " + loginString.Substring(loginString.IndexOf('@') + 1));
         //check with PlayerManager to see if the player already exists
         //if it does not exist create it and add the player to the server.
         createOK();
         //if it does exist call createFail() on the client to give an error and ask them to
         //use a different name
     }
 
     [Command]
     void CmdLoginCharacter(string loginString)
     {
         Debug.Log("Logging in...");
         Debug.Log("Name: " + loginString.Remove(loginString.IndexOf('@')));
         Debug.Log("Password: " + loginString.Substring(loginString.IndexOf('@') + 1));
         //check with PlayerManager to see if the player exists
         //if it does not exist call loginFail() 
         loginOK();
         //if a character does exist then check the password to see if it matches if so addplayer and load
         //player's existing data.
         //if password is wrong then call loginFail()
     }
 
     [ClientCallback]
     void createOK()
     {
         
         ClientScene.AddPlayer(0);
         
         gameObject.GetComponent<Canvas>().enabled = false;
         //fields seem to keep focus after turning the canvas off so just turn them off
         UsernameField.enabled = false;
         PasswordField.enabled = false;
     }
 
     [ClientCallback]
     void loginOK()
     {
         
         ClientScene.AddPlayer(0);
         
         gameObject.GetComponent<Canvas>().enabled = false;
         //fields seem to keep focus after turning the canvas off so just turn them off
         UsernameField.enabled = false;
         PasswordField.enabled = false;
     }
 
     [ClientCallback]
     void createFail()
     {
         //say username is already being used.
     }
 
     [ClientCallback]
     void loginFail()
     {
         //say username or password is incorrect.
     }
 
 }
Comment
Add comment · Show 1
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
avatar image TheFlyingBastard · Apr 30, 2016 at 11:00 PM 0
Share

Have you ever figured out the problem? I'm trying to use an InputField's onEndEdit to call a [command] function in a playerscript which changes a "string playerName" variable in the same class, but it gives me that "Trying to send command for object without authority" error too.

It's weird because when the playerobject (which contains the script) is spawned (going through Start()), it uses that exact same function to change the same variable. It's like the server won't swallow it because it's the InputField that calls that rename function.

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

51 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

Related Questions

,How can I resolve the error “Trying to send command for object without authority.”? 1 Answer

[Networking]How to call a command function from a UI element(a button) 2 Answers

UNET OnTriggerEnter called due to placement of Network-GameObjects on Clients 0 Answers

UNet SyncVar not working 3 Answers

Unity.Networking (UNet) RPC to Specific Player? Master Server? 4 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