• 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 MilesAway1980 · Dec 01, 2015 at 02:36 PM · unity 5networkingcomponents

Networking: Client side objects do not have added components

Hello, I'm working on a networking game and am running into an issue.

I have a prefab object Bullet, and so far, it does fine spawning these and firing them on both the client and the host.

I would like to be able to add components to these bullets depending on certain factors, such as ammo, or options selected.

However, the issue I'm running into is that after I add these components, and then spawn them on all of the clients, only the bullet on the host has the added components.

For example:

 public Class MachineGun : NetworkingBehaviour {
     float size = 0.1f;
     float damage = 10;

     void Start() {
         transform.localScale = new Vector3(size, size, size);
     }

     //This is the prefab loaded into the network manager.  
     public static GameObject getBullet() {
         return (GameObject)Resources.Load ("Prefabs/Bullet");
     }
 }


 public Class Shoot {
     void spawnBullet() {
         GameObject newBullet = (GameObject)Instantiate(MachineGun.getBullet());
         newBullet.AddComponent<MachineGun>();
         NetworkServer.Spawn(newBullet);
     }
 }

As said, this works perfectly fine on the host. The new Bullet has a MachineGun component, and the object scales accordingly.

However, on the client, the Bullet does not have a MachineGun component. It isn't attached to the spawned object.

Is there something I'm missing?
Thanks for any help.

Update: So far I've found this to be a real issue and have found no solution for it. Any help would be great. I've found that the only way around it is to put ALL POSSIBLE components that an object MIGHT have in the prefab and disable them. That way I can enable them when the time comes. This is tedious and obviously not the right way to do it. Any thoughts on this?

Comment
Add comment · Show 5
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 corewise · Jan 18, 2016 at 04:20 PM 0
Share

How come you're not making a separate prefab called $$anonymous$$achineGunBullet?

avatar image MilesAway1980 corewise · Jan 18, 2016 at 04:24 PM 0
Share

That's ultimately what I did for THIS situation, but this was only an example. There are quite a few different instances where I'd want to add a component to an object, especially if they change dynamically during game play. However, the component is only added to the client side object and not the server side, which really is beco$$anonymous$$g a problem.

avatar image corewise MilesAway1980 · Jan 18, 2016 at 04:28 PM 1
Share

I see. The only solution I can think of right off the bat is to tell the client side objects to add components to themselves using an RPC call, and add it on the server as well. Or use SyncVar booleans with hooks to remove/add components.

Show more comments
avatar image Accumulator · Sep 21, 2016 at 04:07 AM 0
Share

Would also love a better solution for this problem!!!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation over network using rpcs 0 Answers

How to make just a simple server to save arrays and vars for a multiplayer? 0 Answers

Question regarding unity mobile multiplayer game 0 Answers

Remote database for leaderboard 2 Answers

Death handling peculiarly 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