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
0
Question by pzeronov · Apr 30, 2015 at 09:20 AM · networkserverrpcinstanceclient

RPC is called but it doesn't destroy some GameObject instances

I have some multiplayer code that it's giving me a bit of a headache. I'm not synchronizing anything over the network as I only need to transfer data between client and server. Only two players can connect (server + client).

When I set up a server and a client connects to it, some prefabs are instantiated in both client and server:

 void OnConnectedToServer()
     {
         print("Server Joined");
         
         // ASK THE SERVER FOR ALL PARAMETERS NEEDED FOR OTHER PARTY RECONSTRUCTION
         nV.RPC("Request", RPCMode.Server);
 
         isConnected = true;
         
     }
 
 [RPC]
     void Request(NetworkMessageInfo info)
     {
         print("SERVER: I just got a request from a client that wants to meet with me");
 
         // spawn units in SERVER
         _enemyUnitOne = (GameObject)Instantiate(enemyUnitOne, _posOne, Quaternion.identity);
         _enemyUnitTwo = (GameObject)Instantiate(enemyUnitTwo, _posTwo, Quaternion.identity);
         _enemyUnitThree = (GameObject)Instantiate(enemyUnitThree, _posThree, Quaternion.identity);
         _enemyUnitFour = (GameObject)Instantiate(enemyUnitFour, _posFour, Quaternion.identity);
 
         // trigger enemy units spawn in CLIENT
         nV.RPC("PlaceUnits", info.sender);
     }
 

That's good so far. The PlaceUnits function looks like this:

 [RPC]
     void PlaceUnits()
     {
         print("CLIENT: placing units...");
 
         _enemyUnitOne = (GameObject)Instantiate(enemyUnitOne, _posOne, Quaternion.identity);
          _enemyUnitTwo = (GameObject)Instantiate(enemyUnitTwo, _posTwo, Quaternion.identity);
          _enemyUnitThree = (GameObject)Instantiate(enemyUnitThree, _posThree, Quaternion.identity);
          _enemyUnitFour = (GameObject)Instantiate(enemyUnitFour, _posFour, Quaternion.identity);
 
         print("CLIENT: units placed.");
     }
 

All of this works perfect. The problem happens when the server clicks on a "Disconnect" button inside OnGUI() that triggers the following:

         // SERVER DISCONNECT BUTTON
         if (isInitialized)
         {
             if (GUI.Button(new Rect(Screen.width/2, 500, 200, 200), "Disconnect", style))
             {
                 
                 // destroy enemy prefabs on SERVER
                 Destroy(_enemyUnitOne);
                 Destroy(_enemyUnitTwo);
                 Destroy(_enemyUnitThree);
                 Destroy(_enemyUnitFour);
 
                 // trigger destruction of enemy prefabs on CLIENT
                 print ("SERVER: ASKING CLIENT TO DESTROY ITS ENEMY PREFABS...");
                 nV.RPC("DestroyEnemiesInClient", RPCMode.Others);
             }
             
         }


And the DestroyEnemiesInClient function:

 [RPC]
     void DestroyEnemiesInClient()
     {
         print ("CLIENT: DESTROYING ENEMIES...");
         Network.Destroy(_enemyUnitOne);
         Network.Destroy(_enemyUnitTwo);
         Network.Destroy(_enemyUnitThree);
         Network.Destroy(_enemyUnitFour);
         print ("CLIENT: ALL ENEMIES DESTROYED.");
 
         // signal SERVER that it is SAFE to DISCONNECT
         nV.RPC("TriggerDisconnection", RPCMode.Server);    
     }


In this last function I tried first with Destroy(instance) and Network.Destroy(instance) but no luck, the objects never get destroyed yet all prints show that the functions are being called correctly in both server and client.

I'd be grateful if anyone could give me some directions as to what I could be doing wrong :/

Best,

Pzeronow

Comment
Add comment
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

1 Reply

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

Answer by hbalint1 · May 02, 2015 at 08:21 AM

Why don't you Netwrok.Instantiate() the objects with master client? so eveyrone will see them, and don't need to instantiate them locally. Also when someone disconnects, the master server could destroy them with Network.Destroy()

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 pzeronov · May 03, 2015 at 07:38 AM 0
Share

Yeah. That's the approach I will eventually use if there's no way to figure out what's wrong with the other method. Anyway, I understand that creating local prefabs on both Server and Client and then triggering their destruction via RPCs should be working too.

avatar image hbalint1 · May 03, 2015 at 07:52 AM 0
Share

I think it can be a problem that you instantiated the objects locallí but trying to destroy the on network. Network.Destroy() is for destroying objects that were instantiated with Network.Instantiate() method. Try changing your Network.Destroy()s to Destroy()s.

avatar image pzeronov · May 03, 2015 at 05:06 PM 0
Share

I tried with both Network.Destroy() and Destroy(). But it won't destroy the local prefabs for whatever reason. Could it be a problem with the variable name?

avatar image hbalint1 · May 03, 2015 at 06:18 PM 0
Share

Interesting. I just found an answer on another forum. Are you sure that your objects are active when you trying to destroy them? If you get stuck and you don't $$anonymous$$d, you can share your project. I can take a look on it.

avatar image pzeronov · May 04, 2015 at 05:41 AM 0
Share

Yeah, it looks like the objects are active before their destruction is called. Alright, I'll see if today after work I have some time to pack it up for you to take a look at.

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Networking RPC calls never sent to other clients 1 Answer

network.RPC behavior 1 Answer

client to client ping - NAT punchthrough 1 Answer

Spawning Clients 1 Answer

RPC Call Mix Up Issues 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