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 Madrig88 · Sep 05, 2016 at 04:33 PM · unity 2dspawning problemsnetwork instantiate

Unable to control prefab when spawned from Network Manager.

I have been fiddling with solutions on this one for a few days without success. I have a prefab set up in the Network Manager's "Registered Spawnable Prefabs" section. However I keep getting errors when I try and spawn it.

alt text

This is the function that spawns the prefab.

 #pragma strict
 import UnityEngine.Networking;

 public class SpawnScript extends NetworkBehaviour {

 private var piecePrefab : GameObject;
 public var pcId : int = 2000;
 
     function NetSpawn () {
         var piecePrefab : GameObject = Instantiate(Resources.Load(pcId.ToString()));
         NetworkServer.SpawnWithClientAuthority(piecePrefab, connectionToClient);
     }
 }

However when I run it it doesn't run as client or authority. Here is the Network Information.

alt text

And these are the errors I get when I try and spawn the prefab:

 Error 1:

 There is no NetworkIdentity on this object. Please add one.
 UnityEngine.Networking.NetworkBehaviour:get_connectionToClient()
 SpawnScript:NetSpawn() (at Assets/Standard Assets/2D/Scripts/SpawnScript.js:286)
 $:MoveNext() (at Assets/Standard Assets/2D/Scripts/SpawnScript.js:62)
 UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

 Error 2:

 NullReferenceException: Object reference not set to an instance of an object
 UnityEngine.Networking.NetworkBehaviour.get_connectionToClient () (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkBehaviour.cs:25)
 SpawnScript.NetSpawn () (at Assets/Standard Assets/2D/Scripts/SpawnScript.js:286)
 SpawnScript+$Start$23+$.MoveNext () (at Assets/Standard Assets/2D/Scripts/SpawnScript.js:62)
 UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
 

Any help would be greatly appreciated. Thank you in advance.

netcomponents.png (29.5 kB)
regspawnprefabs.png (3.8 kB)
Comment
Add comment · Show 1
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 Madrig88 · Sep 05, 2016 at 07:44 PM 0
Share

Is there a different way to do what I'm trying to do?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Madrig88 · Sep 05, 2016 at 10:11 PM

Update:

I was able to move the function (as is) to another GameObject, however the network information is still off and I still cannot control it.

 #pragma strict
 import UnityEngine.Networking;
 
 public class Player extends NetworkBehaviour {
 
     public var pcId : int;
     function NetSpawn () {
 
         var piecePrefab : GameObject = Instantiate(Resources.Load(pcId.ToString()));
         NetworkServer.SpawnWithClientAuthority(piecePrefab, connectionToClient);
     }
 
     function Update () {
     
     }
 }

The Player Network Information:

alt text

The Prefab Network information:

alt text

what gets me about this, is the Player controller ID is -1 and the GameObject its attached to has Player Controller ID is 0. I don't know why its doing this. Any help is GREATLY appreciated.


player.png (15.5 kB)
prefab.png (8.2 kB)
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

52 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

Related Questions

Problem with Coroutines and waitforseconds. 1 Answer

How can i spawn object in different axis using this? 1 Answer

How to increase the spawn rate of an object over time? 2 Answers

Spawn multiple enemies in relation to gameobject [SOLVED] 1 Answer

HI I'm having a problem with spawning objects 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