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 mephistonight · Jun 12, 2017 at 09:12 AM · networkingnetwork.instantiate

NetworkManager class isLocalPlayer equivalent?

Hi all,

I have a question about how the network instantiation of prefabs works.

I'm using a dedicated server, so the host for networking is always my machine.

What I'm trying to achieve is this:

  1. Spawn a prefab on the server that represents a newly connected client (player1) on the server side.

  2. Spawn the same prefab on all clients in order to represent player1 in their scene.

  3. Spawn a different prefab in player1's scene to represent themselves.

The same would be true of all players connecting: a prefab representing themselves in their own scene and a different prefab representing all other players.

In the NetworkBehaviour class I would usually use isLocalPlayer on the player gameobject but of course that public bool doesn't exist because we haven't yet created the local player object.

Is there an isLocalPlayer concept available for use within the NetworkManager class? It seems to me that whilst I can use a public override void OnServerAddPlayer to spawn a prefab on the server and then another override for OnStartClient to spawn prefabs in client scenes, I can't distinguish between a localplayer spawning on the client versus a spawning of a different player's prefab. Below is the code I currently have so you can see what the context is.

Help on this would be much appreciated.

         public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
         {
             GameObject player = (GameObject)Instantiate(remotePlayer, Vector3.zero, Quaternion.identity);
            
             NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
         }
 
         public override void OnStartClient(NetworkClient client) {
             
             
          ClientScene.RegisterSpawnHandler(remotePlayer.GetComponent<NetworkIdentity>().assetId, SpawnPlayer, UnspawnPlayer);
 
                     
             base.OnStartClient(client);
 
             uMMO.get.architectureToCompile = CompilationArchitecture.Client;
 
         }
        
         
         GameObject SpawnPlayer(Vector3 position, NetworkHash128 assetID)
         {
 // How do I know if I'm instantiating a gameobject for the localplayer of a client or if it's a remote player on the local client?
             
             GameObject _object = Instantiate(playerPrefab);
 
             return _object;
         }
 
         void UnspawnPlayer(GameObject inObject)
         {
             Destroy(inObject);
         }



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 mephistonight · Jun 15, 2017 at 02:30 PM 0
Share

@seanr I noticed another thread that you were able to help solve, along similar lines. Would you $$anonymous$$d having a look at the above? Would be very grateful for any advice.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Failure generating network code 1 Answer

what the gameobject belong to if networkidentity do not choose two checkbox ? 0 Answers

networking, online FPS player invisible to others after respawn 0 Answers

Instantiate By ID? 0 Answers

Network.Instantiate/Destroy vs Instantiate/Destroy on each client using [Command] and [ClientRpc] 1 Answer


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