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
1
Question by schoschi · Nov 27, 2017 at 10:08 PM · networkingspawninterfacecommand

Calling Command Function from Client results in "NetworkServer not active..."

Hey!

I have an issue when executing a command from a client. I want to spawn an object using the following code:

 [Command]
     public void CmdHandleTap()
     {
         GameObject instance = Instantiate(projectilePrefab, transform.Find("ProjectileSpawn"));
         instance.GetComponent<Rigidbody>().AddForce(transform.forward * 1000 * instance.GetComponent<Projectile>().speed);
         NetworkServer.Spawn(instance);
     }

However I get the following error when NetworkServer.Spawn(...) is called:

SpawnObject for Projectiles(Clone) (UnityEngine.GameObject), NetworkServer is not active. Cannot spawn objects without an active server. UnityEngine.Networking.NetworkServer:Spawn(GameObject) PlaneController:CmdHandleTap() (at Assets/Scripts/GameObjects/PlaneController.cs:82)


The following things I consider noteworthy:

  • I can spawn a projectile if using a host but only on the host client.

  • Projectile has a NetworkIdentity and a NetworkTransform Component attached.

  • The problem persists for different clients on the same machine as well as different clients on different machines

  • I have been following the UNET tutorial on the official website and spawning objects there was working... I don't find a difference to what I am doing though.

  • I'm using an Interface to access the command functions.


Bottom Line: For some reason I cannot spawn prefabs in a Command Function when called from a client. Can anyone see what I am missing here?

Note: I have noticed the same question being asked a few times already, eg. here. However I have not found an answer yet. Maybe someone can help by now?

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
Best Answer

Answer by schoschi · Nov 28, 2017 at 10:07 PM

I managed to solve the issue. My problem was that I tried to access command methods through an interface.

2 possible solutions:

  • Remove the interface

  • do a two step implementation of the interface methods like this:


Code:

 public interface IController
 {
     void HandleTap();
 }
 
 public class MyController : NetworkBehaviour, IController
 
 {  
     //This will still be executed by the client
     public void HandleTap()
     {
         CmdHandleTap();
     }
 
     [Command]
     private void CmdHandleTap()
     {
         //Code from above
     }
 }


I hope this might help people looking for a similar answer in the future!

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

106 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

Related Questions

Cmd is called on Server ERROR!?!! 0 Answers

UNet - How do I make Network.Spawn not show the prefab to the user that called it? 1 Answer

UnityScript not recognizing NetworkServer "Unknown Identifier" 0 Answers

Why will the raycast not work on the client? 2 Answers

zombie network spawn! help" 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