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
5
Question by ntbsweeps · Mar 04, 2016 at 01:23 PM · prefabmultiplayerplayernetworkmanager

Multiple player prefabs in the network manager?

I'm currently working on a project that allows players to choose their player model (i.e. car model), but Unity's new Network Manager only allows for a single 'Player Prefab' slot.

Initially, I wrote a script that put all player models into an array and I called each one when I switched player models using UI. However, it seems that you can not dynamically switch the Network Manager's player prefab in code.

Next, I tried the terribly long and inefficient method of creating a single prefab containing every player model, and I would disable all other player models that weren't being used. This worked as well, but I could not find a way to save these enabled/disabled choices to the prefab to be used in the Network Manager.

So I'm curious if anyone else has run into this problem or if anyone has found a fix. Trust me, I'm willing to try anything at this point. Thanks a ton!

Comment
Add comment · Show 2
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 jinnindo · Jun 30, 2016 at 06:38 AM 0
Share

Thank you for posting this. I've been looking for an answer, and was leaning towards the second solution you mentioned, so I'm glad to know it's not worth it.

Ideally, there would be an example project of this. I've found several similar forum threads and asks, but honestly I can't understand what's being said, given my limited knowledge.

People seem to think these are solutions, so hopefully the benefit you. http://forum.unity3d.com/threads/unet-spawning-different-player-prefabs-solved.387747/ http://abrgame.blogspot.com/2016/01/using-unet-to-spawn-different-player.html?view=magazine

avatar image CodeElemental · Jun 30, 2016 at 07:35 AM 0
Share

I have no experience working with UNet, i prefer Photon. Have you tried prefabing the type-specific stuff upon creation depending on player speific properties, like selected car, color etc?

CorePrefab[with a creation script attached]

|- SpecificStructure[created by creation script]

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Tubel · Aug 21, 2016 at 08:59 AM

Hey man, I have a solution for you.

 using UnityEngine;
 using UnityEngine.Networking;
 using UnityEngine.Networking.NetworkSystem;
 
 public class NetworkController : NetworkManager {
   
     public Transform spawnPosition;   
     public int curPlayer;
    
 
     //Called on client when connect
     public override void OnClientConnect(NetworkConnection conn) {       
 
         // Create message to set the player
         IntegerMessage msg = new IntegerMessage(curPlayer);      
  
         // Call Add player and pass the message
         ClientScene.AddPlayer(conn,0, msg);
     }
  
 // Server
     public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId, NetworkReader extraMessageReader ) { 

         // Read client message and receive index
         if (extraMessageReader) {
             var stream = extraMessageReader.ReadMessage<IntegerMessage> ();
             curPlayer = stream.value;
         }
         //Select the prefab from the spawnable objects list
         var playerPrefab = spawnPrefabs[curPlayer];       
  
         // Create player object with prefab
         var player = Instantiate(playerPrefab, spawnPosition.position, Quaternion.identity) as GameObject;        
         
         // Add player object for connection
         NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
     }
 }
Comment
Add comment · Show 1 · Share
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 Titanium_Fist · Apr 24, 2017 at 05:01 AM 0
Share

where exactly to attach this script ????

avatar image
1

Answer by ajaybhojani · Jul 15, 2017 at 10:10 AM

Please refer video once

https://www.youtube.com/watch?v=lol2uDGV-_E

Comment
Add comment · Show 1 · Share
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 unity_YTZHhyxnAaMlmg · Apr 20, 2018 at 07:13 AM 0
Share

Link doesn't work/video down.

avatar image
0

Answer by Avedis · Mar 20, 2018 at 04:59 PM

I know it's an old post but @Tubel answer really helped me. I have 2 types of prefabs, a male and female so I need to be able to spawn either one from a login script. I have a custom network manager with overrides based on Tubel's answer, I assign curPlayer via the login script (which is only on the local clients) this in turn tells the server's network manager which prefab from the spawnable list to use for the connecting player. Thanks!

Comment
Add comment · Share
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
0

Answer by Cristian-Serrano-Martinez · Dec 09, 2018 at 02:01 AM

I have the same problem but this not works for me, another idea?

Comment
Add comment · Show 2 · Share
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 jinnindo · Dec 09, 2018 at 06:19 AM 0
Share

Fwiw, my advice is to switch to a different networking solution. https://support.unity3d.com/hc/en-us/articles/360001252086-UNet-Deprecation-FAQ

You might want to consider mirror (it's based on and very similar to unet hlapi, but solves many of it's problems). Also be advised, it seems photon bolt is the only option with p2p.

avatar image stjernerlever jinnindo · May 29, 2019 at 01:44 PM 0
Share

Hi Jinnindo! I'm using $$anonymous$$irror, but when I try to override void OnServerAddPlayer I get the error: no suitable method found to override

Just looking for any solutions to this error!

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

13 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

Related Questions

Network.isServer / isClient not working 1 Answer

UNet changing player prefabs int the network lobby sample. 0 Answers

A name For the Character Please Help 3 Answers

I have problem with synchronize multiplayer player position... 0 Answers

'NetworkTranformChild' problem 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