Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Jigsaw_clr · Mar 13, 2012 at 12:15 AM · networkinginstantiateprefab

Instantiating Multiple Clients into one

Hello Everyone!

I am having trouble bringing in a second player to my server. Everything runs smoothly (server lists, starting servers, ect.) until another client connects to a loaded level. Instead of syncing to each other and instantiating another player in the same game space a second prefab is instantiated on either players client.

So if Player A starts the server. Player A instantiates at the spawn point and can fly around. but when Player B connects. Player B instantiates 2 of the same prefab(within their clients), causes player A's game to instantiate another prefab at the spawn point, and player B controls both prefabs on their side simultaneously. Player A also controls its 2 spawned prefabs simultaneously.

Neither player can be seen by the other.

Obviously there is something I am not doing right but i don't know what it is. Any help would be great!

Instantiate Code:

 var Player : Transform;

 function OnNetworkLoadedLevel ()
 {
     // Instantiating Player when Network is loaded
     Network.Instantiate(Player, transform.position, transform.rotation, 0);
 }
 
 function OnPlayerDisconnected (player : NetworkPlayer) 
 {
     // Removing player if Network is disconnected
     Debug.Log("Server destroying player");
     Network.RemoveRPCs(player, 0);
     Network.DestroyPlayerObjects(player);    
 
 }    
Comment
Add comment · Show 7
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 syclamoth · Mar 13, 2012 at 12:39 AM 0
Share

This is a simple logic error. I can't really see what it is without seeing the code. Can you edit your question to include a snippet of code including the part where your player prefabs get instantiated?

avatar image Jigsaw_clr · Mar 13, 2012 at 04:52 AM 0
Share

I can. The only issue there is the instantiate script matches a script that does work. So i'm thinking that it has to do with my prefab of the plane itself.

avatar image syclamoth · Mar 13, 2012 at 05:16 AM 0
Share

Well, if you are using Network.Instantiate, but calling it once per client, that is one possible cause of the problem. Like I said, it's a simple logic error, but I can't really know which logic error it is without seeing the code.

avatar image syclamoth · Mar 13, 2012 at 05:20 AM 0
Share

And I just realised that you have actually edited your post, but because the folks at QATO haven't solved this bug yet, I can't see the changes. Thankfully, for high-karma users there are workarounds for that...

avatar image Jigsaw_clr · Mar 13, 2012 at 05:21 AM 0
Share

Can't edit for some reason so here.

Instantiate Code:

 var Player : Transform;

 function OnNetworkLoadedLevel ()
 {
     // Instantiating Player when Network is loaded
     Network.Instantiate(Player, transform.position, transform.rotation, 0);
 }
 
 function OnPlayerDisconnected (player : NetworkPlayer) 
 {
     // Removing player if Network is disconnected
     Debug.Log("Server destroying player");
     Network.RemoveRPCs(player, 0);
     Network.DestroyPlayerObjects(player);    
 
 }    
Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by syclamoth · Mar 13, 2012 at 05:19 AM

Try wrapping the 'Network.Instantiate' line in an if-statement that checks to make sure that only the owner can instantiate the object:

 if(networkView.isMine)
 {
     // instantiate things here
 }

Network.Instantiate gets automatically called on all clients, complete with viewID management and buffering. If you want to handle buffering and networkViewID management yourself, you shouldn't use Network.Instantiate.

Comment
Add comment · Show 5 · 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 Jigsaw_clr · Mar 13, 2012 at 05:47 AM 0
Share

Ok awesome, I appreciate the insight, I'll try that. Would there be a reason that this {my version] would work somewhere else though? Because As I said it does work in another example gotten here http://www.unity3dmax.comxa.com/networking.html

avatar image syclamoth · Mar 13, 2012 at 05:54 AM 0
Share

Yes, it would work in the example where there is only ever one object calling that code. I suspect that you have that script on a network-synchronised object, and so the code is being called more than once.

avatar image Jigsaw_clr · Mar 13, 2012 at 06:11 AM 0
Share

Ah i see. So if i instantiate in the way you describe then the NetworkView will bring the object into sync with the others?

avatar image syclamoth · Mar 13, 2012 at 06:26 AM 0
Share

Yes, Network.instantiate does that automatically.

avatar image Jigsaw_clr · Mar 13, 2012 at 11:28 AM 0
Share

I got it. $$anonymous$$is-read the last part. thought you meant to just instantiate it within that if statement not Network.instantiate. I took your advise and a little of my own and came up with the next answer.

avatar image
0

Answer by Jigsaw_clr · Mar 13, 2012 at 11:42 AM

I took syclamoths idea and part of the FPC Controller Motor script and moved them into my movement script.

Using:

 var canControl:boolean;
 
 function Update()
 {
        if(!canControl)
     {
     
     }
     else
     {
           //All movement code
         }
 }
 function OnNetworkInstantiate (msg : NetworkMessageInfo) 
 {
     if(networkView.isMine ==true)
     {
     
         FindParent.target = transform;
         canControl = true;
     }
     else
     {
         canControl = false;
         
         name += "Remote";
     }
 }


This also requires that you the find parent script found in this package (http://www.unity3dmax.comxa.com/networking.html). As well as the networkcam.js in the same package.

Thanks again syclamoth!!

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

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

6 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

The object Player(Clone) must be a prefab in the project view. 1 Answer

Spawning problems with cameras 1 Answer

Network.Instantiate makes 2 objects 0 Answers

Network instantiate command do not execute in all client.. 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