• 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 /
  • Help Room /
avatar image
0
Question by Zjs1316 · Dec 13, 2015 at 11:54 PM · networkingspawningnetwork instantiate

NetworkServer.Spawn() not being called

My I have a command that runs on a player object that spawns a bullet prefab on the server and sets a bunch of its variables to different things but it isn't being spawned when I call NetworkServer.Spawn(bullet);

I have checked and it is being registered, in both the inspector and I tried in code to check to see if I registered it incorrectly but that isn't the issue. I know that it's not being called because I can pause the game, go to the Network Identity and click spawn then the bullet works as intended.

Here is my code:

[Command] void CmdspawnBullet(Vector3 parent, float XPosOff,float ZPosOff, float XNegOff, float ZNegOff, Vector3 scaleFactor, float XSpeed, float YSpeed, float ZSpeed, bool Mover, Vector3 bulletTarget) { //set the transform of the bullet then instantiate and spawn GameObject bullet = (GameObject)Resources.Load ("bullet"); print ("Spawn " + bullet); //bullet.SetActive (true); Vector3 bulletPos = new Vector3(parent.x + XPosOff + XNegOff, parent.y, parent.z + ZNegOff + ZPosOff); ClientScene.RegisterPrefab(bullet); GameObject.Instantiate(bullet, bulletPos, Quaternion.identity); NetworkServer.Spawn (bullet); bullet.transform.LookAt(bulletTarget); bullet.transform.position = bulletPos; bullet.transform.localScale = scaleFactor; bullet.GetComponent<BulletScript>().speedZ = ZSpeed; bullet.GetComponent<BulletScript>().speedY = YSpeed; bullet.GetComponent<BulletScript>().speedX = XSpeed; bullet.GetComponent<BulletScript>().doWeMove = Mover; }

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
0

Answer by fredfishgames · Apr 05, 2017 at 04:04 PM

You need to do

GameObject _bullet = (GameObject)Instantiate(bullet, bulletPos, Quaternion.identity); ClientScene.RegisterPrefab(bullet); NetworkServer.Spawn(_bullet)

The bullet you instantiated must be spawned, not the prefab. This might also have to be called on the server, so you might want to check that before running this.

Hope this helps

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

44 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

Related Questions

What does this error mean? 1 Answer

[UNet] Instantiating over Network won't work 0 Answers

Unity Photon Handle Match Data 0 Answers

NetworkServer is not active. Cannot spawn objects without an active server. 0 Answers

NetworkServer.Spawn() only on Server (with registered prefabs) [Unity 5.2.3f1] 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