Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 am0314 · Jul 07, 2015 at 03:09 AM · c#network

How do clients Use 'NetworkServer.Spawn ();'?

I want the client to create the object

But 'NetworkServer.Spawn ();' it seems only server role

How do I make the client to create was built as a server?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by n1gth · Jul 07, 2015 at 06:25 AM

Ideally, the server should create the object, then all the other clients will know about it too. The client player could use a Command to tell the server to do this.

     [Client] // called only on client
     public void SpawnObject(Vector3 location)
     {
         CmdSpawn(location);
     }
 
     [Command] // runs only on server
     private void CmdSpawn(Vector3 location)
     {
         var obj = (GameObject)Instantiate(MyPrefab, location, someRotation);
         NetworkServer.Spawn(obj);
     }

This assumes that you have NetworkIdentity on your prefab, and that the Player object this is in is a NetworkBehaviour.

Comment
Add comment · Show 3 · 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 am0314 · Jul 07, 2015 at 10:42 AM 0
Share

it worked! Thank you!

I have a better understanding of his principles

Thank you: D

avatar image dogorRafael · Mar 25, 2017 at 08:52 AM 0
Share

If I use a command and inside I call a RpcClient function to instantiate an onbject. I am using only the Instantiate method and it is working, so why use NetworkServer.Spawn? Dont got when i have to use it. What is the difference?

avatar image gon777 dogorRafael · Feb 07, 2018 at 08:15 AM 1
Share

NetworkSever.Spawn will instantiate the object on server as well, therefore the object is a 'networked' object. Your method will only instantiate objects on all clients expect server, in other worlds, they are different local objects ins$$anonymous$$d of a 'networked' object, which means networkbehavior won't work in this case.

This way can be useful if you spawn things like 'explosion animation' which doesn't affect game world, but if you want to interact with this object, for example 'pushing' it, 'destroying' it etc. It will behave differently from client to client.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

C# How to make the gun remember who equipped it 1 Answer

Networked Game Issues - Camera does not follow script 1 Answer

Networking Synchronize Problem. 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