Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Baxter900 · Oct 11, 2015 at 04:02 AM · networkingcomponentsaddcomponentcommand

Adding a component to an object over UNET?

Hey there, this is mostly a question of the best way to do something.

So I want to add components to an object that is networked with UNET (Unity's current networking system), however, if I do that, the new components don't communicate properly. Basically, the big problem I find specifically is that a client can't call commands, even though the identical component was added to the host.

Anyway, I'm just asking for the best way to do this. My current method involves despawning the player then respawning it. But this seems like a horrible way to do this.

Anyway, thanks in advance for help!

Comment
Add comment · Show 1
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 Baxter900 · Nov 06, 2015 at 05:06 AM 0
Share

Anyone have an answer by any chance?

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by seanr · Nov 06, 2015 at 02:11 PM

adding NetworkBehaviour components to spawned objects at runtime is not supported.

Comment
Add comment · Show 1 · 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
avatar image Baxter900 · Nov 07, 2015 at 06:34 PM 0
Share

Well that sucks...

Alright thanks!

avatar image
0

Answer by HarvesteR · Aug 14, 2019 at 05:20 PM

There is a way around that though. I've implemented it here successfully. Mind that it's not what I'd call a simple approach. It requires things to more or less be built around it.

The idea is to create prototypes of the objects you want to spawn, with all their optional components pre-attached, and keep them disabled somewhere, as a sort of runtime prefab. Then, for each of those prototype objects, you set up a custom spawn handler (using a unique id for each). In that spawn handler method, you instantiate the prototype object you created.

It's not really the same thing as adding components at runtime, because the components do need to be added in advance for each prototype object, but if you're making things that use script components as behaviour modules, then this approach works well. Different types of objects can have different sets of modules.

This approach worked for me because it made sense to keep the object prototypes cached in my project, but it can be generalized to do objects with components added completely at runtime, what you'd do is create a logic object factory system, which creates prototypes on request, by setting up an empty gameobject, attaching components to it (along with network identity and all), and registering a spawn handler to instantiate that object, then you can call NetworkServer.Spawn with that object's unique ID.

I know this is a bit late, because UNET is on its way out already, but for those of us that are version-locked into using it, this is a way to do it.

Cheers

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

36 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

Related Questions

[Command] not working properly? 0 Answers

UNET Server not setting [SyncVar] 0 Answers

Command cannot pass GameObject parameter from remote client to server. 6 Answers

NetworkServer.Destroy(GameObject) disables Client objects instead of destroying them 1 Answer

Can I use Rpc Calls and Commands on the same object? 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