Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 cppnick · Feb 19, 2012 at 01:15 AM · c#prefabnetworkrpc

Send Prefab by RPC?

How can I send a prefab by RPC?

Right now, I am sending prefab's as strings, and calling Resource.Load() on everyone that receives the RPC, but this is very inconvenient, because it forces me to keep all my prefabs in the resource folder, and also to manually type out the names of all the prefabs.

In the documentation for Network.Instantiate, it says that unity uses an "identifier" for the prefab and sends an RPC. Where exactly does this identifier come from?

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 Jozxyqk · Dec 30, 2012 at 02:25 AM 0
Share

I would very much like to see this question answered. Unity's networking is severely lacking. The least they could do is expose enough internals to let us fix their mistakes.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by syclamoth · Feb 19, 2012 at 01:24 AM

Well, since presumably both computers already have the prefab (because it was packaged with the game), all you need to do is send a 'signal' RPC which includes a 'NetworkViewID'- this will allow you to synchronise two objects, assuming that they are compatible.

When the signal RPC arrives, the receiver should spawn the correct prefab, and the assign the received NetworkViewID to the newly created object's networkView.viewID field.

So, all you need to do is assign the prefabs in the inspector, like normal, and then just make sure that they have networkViews, and that the instantiation happens in an RPC call that knows what prefab to spawn. Remember that unless you change the references at some point (which is always going to be a problem for prefab instantiations), it will just work.

Comment
Add comment · Show 4 · 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 cppnick · Feb 19, 2012 at 08:40 AM 1
Share

That won't really work in my case. Basically, what I am trying to do, is create a custom Network.Instantiate that sends a reference to the NetworkPlayer that Instantiated the prefab along in the same RPC. The unity docs say that I should be able to get that information in OnNetworkInstantiate() from either info.sender or networkView.owner, but the data in those two variables is very inconsistent. In many cases, they can contain -1(empty), or 0(the server) even when it was a client that initially called for the instantiation... So how am I supposed to know who instantiated something?

avatar image cppnick · Feb 19, 2012 at 08:48 AM 0
Share

this post also talks about the issue above: http://forum.unity3d.com/threads/51312-networkView.owner-issue

avatar image syclamoth · Feb 20, 2012 at 05:00 AM 0
Share

Ah, I've had this exact problem before. In the end what I had to do was create (when a player joins) a 'Player' object that was definitely owned by the newly spawned player. Then, I could use references to it, ins$$anonymous$$d of relying on networkView.owner etc.

avatar image cppnick · Feb 21, 2012 at 01:47 AM 0
Share

yea, that still left me with the problem of manually sending the rpcs so I could send that reference along. I ended up just making a persistent GameObject with a list of all the prefabs that, which sets an index in each prefab's base class when the game starts, which allows me to just reference the prefabs by an integer index. Definitely not ideal, but it does the trick.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

RPC replace the existing list on all players 0 Answers

Slow time for every enemy at a certain distance from inside RPC 1 Answer

How To Deal With Lingering Prefabs in Multiplayer Scene ? 0 Answers

Distribute terrain in zones 3 Answers

Show prefab's children over network 1 Answer


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