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 /
  • Help Room /
avatar image
0
Question by Kendom · Apr 02, 2017 at 07:10 PM · multiplayergetcomponentprefabsmultiplayer-networkingnetwork instantiate

Trying To Spawn a Modified Prefab with NetworkServer.Spawn doesn't work.

Hello fine folks. You see, I've been trying to get along with multiplayer to attempt new features and online play. As such, i'm still very newb in these aspects.

Getting straight to the point: I have an extremely simple Asteroids esque space shooter, where the goal is for the players shoot each other to death. I got nearly everything synced properly but one critical thing doesn't work.

The bullets that are spawned shoot the player that spawned them.

This is because bullets use an "OwnerID" to identify which player owns the bullets so he doesn't get shot by his own bullets. Bullets that have custom "OwnerIDs" have been Initialized by the player with that ID thingy and also the same color as the player. So white bullets effectively have no Owner because they haven't been initialized. (They have white as default color and default Owner ID)

This is what happens when I attempt NetworkServer.Spawn(), it basically spawns the default bullet, causing the players to kill themselves, but on the host side, everything's fine and working normally.

How do I fix this?

    void PewPewPew() // This is a bridge for the lack of a better term...
     {
            
         CmdInstantiateNetworkBullet();         
 
     }
     
     [Command]
     public void CmdInstantiateNetworkBullet()
     {
         BI = (GameObject)Instantiate(Bullet, transform.position, Quaternion.Euler(0, 0, transform.eulerAngles.z - 90));
         BI.GetComponent<BulletScript>().InitializeVars(OwnerID, PColor);             
         
         NetworkServer.Spawn(BI);
                 
     }

To add, I tried to follow the Multiplayer FPS tutorial as closely as possible, their method works on my side, but I have to change the bullets to make them color coded and to prevent self shooting .Maybe I missed a step or something.

Well thanks for Reading! :)

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 gary-au-83-ga · Apr 03, 2017 at 08:08 AM 0
Share

I'm in the same situation, after the update to 5.6, the projectile that worked and showed up on the client stop working and giving error message "OnObjSpawn netId: 45 has invalid asset Id" while when hosting it don't. Please help, really need network for my project.

avatar image Kendom gary-au-83-ga · Apr 03, 2017 at 08:25 AM 0
Share

I ended up getting help on a Reddit thread, and a person suggested for me to use ClientRPC to fix the code. So it generates bullets on both the Clients and the Servers, it probably isn't the cleanest approach but it works great for now. :)

This worked for me, not sure about your problem tho.

  [Command]
     public void CmdInstantiateNetworkBullet()
     {
         BI = (GameObject)Instantiate(Bullet, transform.position, Quaternion.Euler(0, 0, transform.eulerAngles.z - 90));
         BI.GetComponent<BulletScript>().InitializeVars(OwnerID, PColor);
         transform.localScale *= 0.8f;
         // NetworkServer.Spawn(BI);
         RpcInsantiateClientBullets();
        
     }
     [ClientRpc]
     public void RpcInsantiateClientBullets()
     {
         BI = (GameObject)Instantiate(Bullet, transform.position, Quaternion.Euler(0, 0, transform.eulerAngles.z - 90));
         BI.GetComponent<BulletScript>().InitializeVars(OwnerID, PColor);
         transform.localScale *= 0.8f;
     }

avatar image gary-au-83-ga Kendom · Apr 03, 2017 at 08:34 AM 0
Share

Guess i can give it a try, so do i need to add the "Network Identity" component to my projectile gameobject?

Show more comments
Show more comments
avatar image Kendom gary-au-83-ga · Apr 04, 2017 at 03:57 PM 0
Share

An RTS is a tad ambitious compared to a simple arena shooter, don't you think?

The [ClientRpc] simply runes that code on the clients, while [Command] runs it on the server. I'm really new to this stuff so I'm sorry I can't help you as much as I would have liked.

Also the InitializeVars() is a method that Is run on the bullets and gives them their look n stuff. I have to run it twice on both [Command] and [ClientRPC] so it creates the bullets "correctly" on all clients and the server, still this doesn't stop some $$anonymous$$or desync issues, since they are created with delay and sometimes can miss in some clients and hit in others. $$anonymous$$y future solution to this is have the Server "sync" the proper variables periodically.

Also I have no idea what Network.Identity does, I just put it in there to prevent issues. $$anonymous$$aybe I don't need it. Who knows.

Best of luck in your game.

Also, I don't use a "weapon" everything is in the same player script. Except for the bullets, but their code is just angle based motion, the actual creation part was what originated this question.

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

131 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 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

I'm using Unity MLAPI. Why does every client have id "0"? 0 Answers

Unet: Is the position in a GameObject Inspector hierarchy important 0 Answers

Unity ad hoc Android multiplayer possible ? 1 Answer

Increasing CCU's on UNet?? 0 Answers

Multy Player both players are moving 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