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 Mattrhorn · Oct 26, 2018 at 04:25 AM · multiplayerserverclienttheory

UNet Server-Client Command Functions Help

HI, Im creating a UNet Board Game thats based on manipulating path Game Objects. My goal is to place all of the Path Gameobjects (which have scripts attached to manage it) into the Servers paths[] array (of Paths which is the script attached). I want the Server to be the only one who manages the array and relay the information back to the client.

I have setup the Player Script that Calls a [Command] Function which populates the paths[] array with the Path Game Objects Components that are already in the server (there are 81 objects before the player joins). This appears to be populated correctly as I can see the values of the game object when called, and the Path Variables sync across all clients properly.

For some reason when I try to issue a [Command] to change the variables on a paths[] variable, if the Command wasnt called by the player who called the initial Command to populate that paths[] array, it would return a null reference error. Why is that? From my understanding, if the function is a [Command], it should be performed on the server. So when the Inital population is called as a command it should populate the server's paths[] array. How come it returns null references to the clients who didnt initiate that command? I have left 3 Blocks of code below. The first explains the scenario and outcome above, the 2nd is the paths[] populating Command, and the 3rd is the command that changes the value in one of the paths[]. I have spent days trying to understand why this occurs, please help me, ive checked everywhere with no explanation found!

  //I have denoted the 2 connections as Host and Client, CmdSetupPaths sets up the paths (btn3) and CmdCheckPaths checks if the path exists
 // [FunctionCall1] : [FunctionCall2] -> [Output of FunctionCall2]
 
 //     Host.CmdSetupPath : Host.CmdCheckPath -> True
 //     Host.CmdSetupPath : Client.CmdCheckPath -> False
 //     Client.CmdSetupPath : Host.CmdCheckPath -> False
 //     Client.CmdSetupPath : Client.CmdCheckPath -> True

 [Command] private void CmdGetPathsFromGame(){
         if(!isServer){
             Debug.Log("Not the Server... Exiting");
             return;
         }
         bool foundAllPaths = true;
         for(int i=0; i<9; i++){
             for(int j=0; j<9; j++){
                 string pathName = "Path " + i.ToString() + j.ToString();
                 paths[i,j] = GameObject.Find(pathName).GetComponent<Path>();
                 if(paths[i,j]==null)
                     foundAllPaths = false;
             }
         }
         if(!foundAllPaths)
             Debug.Log("FAILED TO FIND ALL PATHS");
         else
             Debug.Log("FOUND ALL PATHS");
     }

 [Command] public void CmdSetGenState(int i, int j, bool n){
         if (!isServer){
             Debug.Log("Not Server... Function Returned");
             return;
         }
         Debug.Log("Changing Path: " + i + j + " to " + n);
         paths[i,j].GenStateChange(n);
         if(paths[i,j].hasGen == n)
             Debug.Log("Change Successful");
         }
     
     }

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

223 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 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

What is difference between Network.InitializeServer and Unet. please help me 0 Answers

API for multiplayer game with authoritative server? 1 Answer

How to allow All clients to move blocks? 0 Answers

Destroy only player after disconnecting from server 0 Answers

multiplayer game -how to connect each game-object to specific network player 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