Author Topic: Multiple rfc calls during lag, tips to avoid?  (Read 1815 times)

thelebaron

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 15
    • View Profile
Multiple rfc calls during lag, tips to avoid?
« on: April 19, 2014, 08:43:22 PM »
Alright I have a simple setup where an rfc will be called during the death of an object, but I am assuming that when there is lag due to physics, it seems like the rfc gets called a bunch of times.  I'm not really sure how to prevent this, any tips?

video example https://onedrive.live.com/#cid=8D4EBD699F0CC823&id=8D4EBD699F0CC823%2114400&v=3


  1.  
  2.                 if(TNManager.isHosting && health <= 0)
  3.                 {
  4.                         // Die if no health left
  5.  
  6.                         tno.Send ("NetworkDestroyObject", Target.AllSaved);
  7.                
  8.                 }
  9.  
  10.  
  11.  
  12.  
  13.         [RFC]
  14.         public void NetworkDestroyObject()
  15.         {
  16.         Debug.Log("Killobject d Received");
  17.         if (TNManager.isHosting)
  18.                 {
  19.                 TNManager.Create(ragdollPrefab, this.transform.position, this.transform.rotation);
  20.                 //Debug.Log("Hosted object should be destroyed!");
  21.                 TNManager.Destroy(this.gameObject);
  22.                
  23.                 //Destroy(gameObject);
  24.                 }
  25.    }
  26.  

These are the bits specifically that handle the death bit.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Multiple rfc calls during lag, tips to avoid?
« Reply #1 on: April 19, 2014, 11:29:15 PM »
That depends on where you call it from. You don't seem to be setting any kind of a flag there that indicates that you've already sent the destroy call.

Also you are sending this notification to everyone... not sure why. You're checking TNManager.isHosting inside -- so only one player can effectively receive it and execute the code inside. Wouldn't it be easier to get rid of that function altogether, and just do both TNManager.Create and TNManager.Destroy calls where you're calling the RFC? It's also inside if (TNManager.isHosting) after all...

And don't forget to set some "destroyed" flag, or this code will execute again on the next update (assuming that's where you put it).