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 DanB · Jun 15, 2016 at 03:20 PM · networkingspawningnetworkviewnetwork.instantiatenetworkviewid

Network.Instantiate and NetworkServer.Spawn not working

Hi!

I'm trying to create a multiplayer game in Unity. I want to spawn a few cubes when the server starts, but nor Network.Instantiate nor NetworkServer.Spawn is working.

When I try to call Network.Instantiate() the error is "Failed Network.Instantiate because we are not connected."

When I use NetworkServer.Spawn(), the objects do get spawned, but they all have the same network viewID (0). If I try to allocate the viewId manually, I get the error that I should increase the minimum client networkViewId count. I don't have any other objects in the scene, and also I tried setting it to 500, but the error remains.

The script runs Server Only.

The script itself:

 int itemsToSpawn = 6;
 List<GameObject> itemPrefabs = new List<GameObject>();
 
 void Start()
     {
     for ( int i = 0; i < itemsToSpawn; i++)
         {
         Network.Instantiate(itemPrefabs[random], position, location, 1);
         }
     }
 

I also tried OnStartServer() instead of Start(), did not change anything. itemPrefabs is a List of prefabs assigned throug the inspector, currently there is only a cube in it.

Also instead of Network.Instantiate, I tried using NetworkServer.Spawn(), like this:

     int itemsToSpawn = 6;
     List<GameObject> itemPrefabs = new List<GameObject>();
     
     void Start()
         {
         for ( int i = 0; i < itemsToSpawn; i++)
             {
             GameObject item = (GameObject)Instantiate(itemPrefabs[random], position, location);
             NetworkServer.Spawn(item);
             }
         }

Thanks for the help.

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 EpiFouloux · Jun 15, 2016 at 04:13 PM 0
Share

show us the code, we can't help with so few information

avatar image DanB EpiFouloux · Jun 15, 2016 at 05:30 PM 0
Share

Sorry, added now!

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Orami · Jun 16, 2016 at 12:09 AM

Please note if you are using Unet you need to register prefabs with the Network Manager script. You can find this area by looking under spawn info and there is a list called Registered Spawnable Prefabs. If it says you are not connected you are probably not local hosting or connected to a server which you would need to do to make the NetworkServer.Spawn(go); code work.

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 DanB · Jun 16, 2016 at 07:27 AM 0
Share

I already registered it as a spawnable prefab in the Network $$anonymous$$anager. And I am using the default Network $$anonymous$$anager HUD to start the game as a host, so that couldn't be the issue.

avatar image Orami DanB · Jun 16, 2016 at 07:29 AM 0
Share

Try adding a network manager HUD script to it (built in)

avatar image
0

Answer by Recurring · Feb 08, 2018 at 10:55 AM

I know this is a bit late, but all you need to do is create something like this:

 [command]
 void Cmd_SpawnItem(){
              GameObject item = (GameObject)Instantiate(itemPrefabs[random], position, location);
              NetworkServer.Spawn(item);
 }

and just call that function from Start().

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get NetworkViewID and GameObject attached to NetworkViewID 1 Answer

Unet: Spawner spawns for every player one object instead of just one 0 Answers

Hello, I created a script to add the NetworkView of the player to "public NetworkView nV", but it's working only if the client is the host. 0 Answers

Networking | Getting buffered other - previous spawned players 1 Answer

Convert Network.ViewID to Int 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