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
2
Question by KaiserJohan · Jan 16, 2012 at 09:00 AM · androidnetworkingnetworkwindows

Sending a gameobject over network with RPC?

Hello,

I am having the exact same problem as this post: http://answers.unity3d.com/questions/11113/buffered-rpcs-from-networkinstantiate-not-removed.html I've also read the RPC details: http://unity3d.com/support/documentation/Components/net-RPCDetails.html

So there I read the answer AngryOldMan, which sounds like a good solution. The problem is, I can't send GameObjects using RPC calls ("not supported" in unity the error says). How do I solve this then if I cant send the objects?

For example, here's what my clients execute:

     public void ClientKillFrog(GameObject frog)
     {
             // send a request to the server to kill a gameobject
         networkView.RPC("OnClientKillFrog",RPCMode.Server, frog);
     }
     
     [RPC]
     void OnServerKillFrog(GameObject frog)
     {
            // server has ack'd a clients need to kill a gameobject
         Destroy(frog);
     }

And here's the server:

    [RPC]
     void OnClientKillFrog(GameObject frog,NetworkMessageInfo info) 
     {
         Debug.Log("OnClientKillFrog");
         networkView.RPC("OnServerKillFrog",RPCMode.AllBuffered,frog);
     }


UPDATE: OK, solution by jet.c works in some cases, but I have one more problem: When I have a server running and 1 client playing, killing and spawning some frogs, then when another client connects I get this:

 View ID AllocatedID: 1 not found during lookup. Strange behaviour may occur
 Couldn't perform remote Network.Destroy because the network view 'AllocatedID: 1' could not be located.
 ....

I assume this is because the newly connected client tries to perform Network.Destroy on objects already destroyed for everyone else, so the server crashes. How do you handle this?

Comment
Add comment · Show 3
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 Bunny83 · Jan 16, 2012 at 10:20 AM 1
Share

Do you use Network.Instantiate for all objects that have to interact over the network? You have to understand how networking works. Every peer has it's own objects. They have nothing in common except the NetworkViewID. This ID has to be unique across the whole network and link the objects on different PC into one object.

If you create an object you have to create it on all clients as well. Network.Instantiate does this for you. It also stores a buffered RPC that tells new connected players which objects has been created in the past. When you destroy an object with Network.Destroy (which destroys the local object and tells all clients to destroy their object with the same NetworkViewID) you also have to remove the buffered RPCs with Network.RemoveRPCs to prevent new clients from creating / destroying objects that doesn't exist anymore.

avatar image Bunny83 · Jan 16, 2012 at 10:29 AM 0
Share

btw. The question you refer to is outdated. Back these days there wasn't a Network.RemoveRPCs that takes a NetworkViewID as parameter.

This function has been introduced in Unity 3.2 as you can read here: UpdateNotes Unity 3.2(see "Other Improvements"). So you also have to be careful with tutorials before that release since there has been invented a lot complicated workarounds.

avatar image KaiserJohan · Jan 16, 2012 at 10:40 AM 0
Share

I see, big thanks

2 Replies

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

Answer by jef.c · Jan 16, 2012 at 09:09 AM

Rather than sending a GameObject through the RPC, try sending its NetworkViewID instead.

Comment
Add comment · Show 6 · 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 KaiserJohan · Jan 16, 2012 at 09:33 AM 0
Share

but how do you call Destroy on it then? since you cant just Destroy on a networkViewID. Ive tried Network.Destroy() but it keeps throwing me exceptions such as "View ID AllocatedID: 2 not found during lookup. Strange behaviour may occur" during runtime

avatar image jef.c · Jan 16, 2012 at 09:38 AM 0
Share

Network.Destroy() accepts a NetworkViewID as a parameter.

avatar image KaiserJohan · Jan 16, 2012 at 09:52 AM 0
Share

updated question

avatar image jef.c · Jan 16, 2012 at 09:58 AM 0
Share

Try clearing the RPCs on it right before you destroy it: Network.RemoveRPCs( networkViewID );

avatar image KaiserJohan · Jan 16, 2012 at 10:11 AM 0
Share

That worked nicely, huge thanks1

Show more comments
avatar image
0

Answer by elliselkins · Nov 01, 2017 at 09:17 PM

Turns out you can have a GameObject parameter in an Rpc or Command function (see the Arguments to Remote Actions section). The GameObject must have a NetworkIdentity component, so it must either be in the scene when the application runs or after it is instantiated then it must be spawned with NetworkServer.Spawn.

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

7 People are following this question.

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

Related Questions

Question about Network.Destroy 0 Answers

Network - Client still in Network.Connections after disconnect 2 Answers

Question about Network and NetworkViewID 1 Answer

Run several unity clients at once in windows? 0 Answers

Unity Multiplayer Design. Is it complicated to implement and learn? 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