Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 mradrielo · Aug 15, 2015 at 03:55 AM · unity multiplayer

[C#] Unet spawn dont work.

Hi! I have this code:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Networking;
 
 public class PlayerShooting : NetworkBehaviour {
 
     [SerializeField] GameObject BulletObj;
     public Transform BulletSpawn;
 
     void Start(){
         BulletObj = (GameObject)Resources.Load("Prefabs/Bullet");
         if (!isLocalPlayer) {
             enabled = false;
         }
     }
 
     void Update () {
         if (Input.GetButtonDown ("Shoot")) {
             CmdSpawnBullet(BulletSpawn.position);
         }
     }
 
     [Command]
     void CmdSpawnBullet(Vector3 pos){
         GameObject Bullet = (GameObject)Instantiate (BulletObj, BulletSpawn.position/*new Vector3(transform.position.x,0.328f,transform.position.z)*/, this.gameObject.transform.rotation);
         ClientScene.RegisterPrefab(Bullet);
             NetworkServer.Spawn (Bullet);    
     }
 
 }
 

1- This code should instantiate a bullet. This work in the server, but when you press the fire button in the client, the bullet dont spawn...

2- I have this error in the console when i spawn the bullet correctly in the server: alt text

This have no sense, because i attach the "bulletspawn" and the bullet spawn on the server and client...

Comment
Add comment · Show 6
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 JoshuaStrunk · Aug 15, 2015 at 07:46 PM 0
Share

I am not sure about your error it could have something to do with using a Command, but don't quote me on that. I don't think you should have to spawn the bullet through a Command on the server. See how they do it here.

avatar image mradrielo · Aug 15, 2015 at 08:01 PM 0
Share

Ok the problem of instantiate is solved, but the error message persist... And this have no sense x´D

avatar image JoshuaStrunk · Aug 15, 2015 at 09:46 PM 0
Share

Without seeing inspector for PlayerShooting hard to tell. From you other post you did not have anything assigned so it would be your standard null ref exception.

avatar image mradrielo · Aug 15, 2015 at 09:50 PM 0
Share

I think this is a Unity bug: alt text

alt text

alt text

avatar image JoshuaStrunk · Aug 15, 2015 at 09:52 PM 0
Share

What does the inspector look like on the object when you in play mode in the editor and get the error. See if the referenced object is getting unreferenced when you play.

also I would edit your original posts code to reflect the changes you made.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Change NetworkMatch's name, attributes, and password after creation 1 Answer

Unity 2017 Unet - Dedicated Server 1 Answer

UNET Network Discovery sends data with extra characters 0 Answers

ListMatchResponse Matches Count is 0 on remote PC?!? Why is Matchmaking broken? 0 Answers

Several Unity Multiplayer questions 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