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 oliver-jones · May 01, 2014 at 03:19 PM · networkingphotonrpc

Photon/Network - Killing A Client Enemy Unit

I've already asked this on the Photon forum, but I suppose this is also a Unity Network question too, so apologies for double posting in a different forum.

I'm wondering what the best approach is for my unit to attack, send damage, and kill across a network (photon specifically). Currently, everything works just as expected, but I occasionally get warning about Receiving RPCs for PhotonViews that don't exist, possibly because its been destroyed/killed. I just want to know if I'm doing it correctly, to prevent further errors/issues down the line.

"Received RPC "UnitDead" for viewID 1004 but this PhotonView does not exist! View was/is ours. Remote called". "Received RPC "RecievingDamage" for viewID 1004 but this PhotonView does not exist! View was/is ours. Remote called".

Okay, so what happens is that my player locally fires a raycast to an enemy unit, and sends 'RecievingDamge' to the target via RPC:

 if(hit.collider.gameObject.tag == "Unit"){
     var targetID = hit.collider.gameObject.GetComponent(PhotonView);
     targetID.photonView.RPC("RecievingDamage", PhotonTargets.All);
 }


Then, on my enemy unit, I have the receiver:

 @RPC
 function RecievingDamage(){
 
     currentHealth -= 5;
     Health.system.SetActive(true);
 }

Then, to kill the unit, I do this locally:

 if(currentHealth <= 0 && !isDead){
     photonView.RPC("UnitDead", PhotonTargets.All);
 }
 
 @RPC
 function UnitDead(){
 
     isDead = true;
     Instantiate(explosion, transform.position, transform.rotation);
 
     if(photonView.isMine){
 
         //remove selves from UnitManager
         GC.UM.RemoveUnit(transform);
         PhotonNetwork.Destroy(photonView);
     }
     //Destroy(gameObject);
 }

I sure would appreciate any feedback, am I doing this correctly? I think my main issue here really is the 'PhotonNetwork.Destroy(photonView);', maybe I should destroy the unit locally on every client? Thanks

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 Arkaic · May 14, 2014 at 05:20 AM 0
Share

I sure with someone would answer these. I have spend easily 8 hours trying to get the proper way of destroying the enemies over a network.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by skylem · Aug 20, 2014 at 05:38 AM

i've achieved this, first i photon.instantiate my enemies on create room, (im new to photon and this was only way i knew how to go about it there is probably better methods) then set a boolean, have to ask though did u try, PhotonNetwork.Destroy(photonView.gameObject); ? try setting up a second boolean, send its value to the owners script to set ur initial bool isDead true then add that boolean as a parameter inside the is mine section, i would have submitted example code but my pc isn't letting me so if u still need help email me, skyle.mcneill@gmail.com

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
avatar image
0

Answer by SniperEvan · Oct 26, 2014 at 09:35 PM

I haven't done it yet but I've been planning a PhotonNetwork implementation for a few days now. My system will involve casting spells to deal damage. The system is slightly different then yours and rellys on the master client to kill enemies and synchronize it across each cient.

Step 1. Cast spell using RPC. This will create the same spell on every client. Step 2. Hit enemy, and check if I am the master client. I apply damages locally but dont destroy gameobjects. Step 3. If the enemy's health is <1 && I am master client I use PhotonNetwork.Destroy to remove the enemy.

Theoretically this will eliminate the lost RPC calls that happen when you call [RPC] DamageEnemy(). Instead of sending DAMAGE across a server and discovering that the enemy has been destroyed already on that client, we only send ATTACK data over the server and then let the Master Client decide if the enemy should be removed or not. The enemies can still be damaged locally by the attacks but only the Master decides when to remove them over the network.

I haven't implemented this yet but I think it will work. Every client should have the same gameobjects in place until the buffered PhotonView.Destroy() method removes them.

Sorry if the solution came too late to help you (I know its been a couple of months since you posted) but hopefully this solution works for others.

~E

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
avatar image
0

Answer by InfernoZYB · May 22, 2015 at 03:52 AM

Maybe try doing

 PhotonNetwork.Destroy(this.photonView);
 
 That's what seems to work for me.
 
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

25 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

Related Questions

Photonview "this" does not exist in current context 1 Answer

Send gameobject through photon RPC 1 Answer

Photon Network Instantiate Objects over Network 1 Answer

Cheating possible in this code? 1 Answer

[Photon] Restart scene rpc doesn't work 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