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 Akusan · Dec 28, 2016 at 01:33 AM · networkingmultiplayermultiplayer-networkingspawningspawning problems

Why are objects only spawning on host but not on remote clients?

Why is the following code not spawning objects on both host and remote clients? How can I modify this code to make objects spawn on both host and remote clients? Is there a better solution?

 using UnityEngine;
 using UnityEngine.Networking;
 
 public class CatSpawner : NetworkBehaviour
 {
     public int numberOfCats;
     public GameObject catPrefab;
     
     public override void OnStartServer()
     {
         for (int i = 0; i < numberOfCats; i++)
         {
             var spawnPosition = new Vector3(
                 Random.Range(-64.0f, 100.0f),
                 106.0f,
                 Random.Range(34.0f, 184.0f));
 
             var spawnRotation = Quaternion.Euler(
                 0.0f,
                 Random.Range(0, 180),
                 0.0f);
 
             var cats = (GameObject)Instantiate(catPrefab, spawnPosition, spawnRotation);
             NetworkServer.Spawn(cats);
         }    
     }
 }

My object Prefab has Network Identity and Network Transform component. The Game Object with the spawning script has Network Identity. I don't see the problem. ObjectPrefab

GameObject

catprefab.jpg (48.6 kB)
cat-spawner.jpg (27.2 kB)
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

3 Replies

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

Answer by LK84 · Dec 28, 2016 at 10:23 AM

Remove the ServerOnly checkmark (and don't use the Local Player Authority checkmark either!) and register the prefab in the Network Manager!

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 Akusan · Dec 28, 2016 at 10:40 AM 0
Share

This worked! Thanks! :-D

avatar image MostHated · Mar 17, 2018 at 10:51 AM 0
Share

You have to be kidding me. I spent 6 hours tonight making 7 different builds, waiting for them to upload to my server, I set up a second pc eventually so I could try to host here and connect locally so I could better see what why my character would never spawn, only to finally find out he was actually spawning just not on my client pc. So I search that after finally figuring out what was happening to find out it was a mother f* checkbox. I am new to networking in Unity obviously, I thought that since it was right above the "Local Authority" box that when it said "Server Only" It was referring to authority also, and since I am making an RPG I thought to myself, "well yeah, I definitely want server authority only". fml...

avatar image BluezamX MostHated · Nov 22, 2019 at 03:26 PM 0
Share

You don't need another PC / server to test multiplayer. Just run the host from the Unity Editor, and run the build and connect to your localhost (default 7777 I believe). This way you can test online functionality on one PC, while still being able to view the console.

avatar image
0

Answer by marcrem · Dec 28, 2016 at 01:53 AM

I might be wrong, but you need to use [Command] on a void which name starts with Cmd.

https://docs.unity3d.com/ScriptReference/Networking.CommandAttribute.html

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 Akusan · Dec 28, 2016 at 03:27 AM 0
Share

Thanks for the response but I tried using Command too but I get the same results.

 using UnityEngine;
 using UnityEngine.Networking;
 
 public class SpiderSpawner : NetworkBehaviour
 {
     public int numberOfSpiders;
     public GameObject spiderPrefab;
 
     void Start()
     {
         CmdSpawn();
     }
 
     [Command]
     void CmdSpawn()
     {
         for (int i = 0; i < numberOfSpiders; i++)
         {
             var spiderPosition = new Vector3(
                 Random.Range(-64.0f, 100.0f),
                 106.0f,
                 Random.Range(34.0f, 184.0f));
 
             var spiderRotation = Quaternion.Euler(
                 0.0f,
                 Random.Range(0, 180),
                 0.0f);
 
             var spiders = (GameObject)Instantiate(spiderPrefab, spiderPosition, spiderRotation);
             NetworkServer.Spawn(spiders);
         }
     }
 }

avatar image
0

Answer by ElijahShadbolt · Dec 28, 2016 at 06:35 AM

The 'SmallCat' GameObject's NetworkIdentity has 'Server Only' set to true. I don't know much about Unity's networking system, but I think 'Server Only' would indicate it only spawns on the Host/Server, wouldn't it?

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 Akusan · Dec 28, 2016 at 10:00 AM 0
Share

I thought that was it too but even having Local only selected does not work:

alt text

spider-local-only.jpg (100.1 kB)

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

111 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

Related Questions

Only host can spawn objects on server, when the client tries to spawn an object it returns the error, "NetworkServer is not active. Cannot spawn objects without an active server." 0 Answers

Only host can spawn objects on server, when the client tries to spawn an object it returns the error, "NetworkServer is not active. Cannot spawn objects without an active server." 1 Answer

Check when a player finished spawning [Netcode For GameObjects!] 2 Answers

Unity networking tutorial? 6 Answers

Host Can Spawn Objects on all clients screen while the client can only spawn objects on their screen. Client Cannot Spawn Objects On The Server 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