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 24, 2012 at 10:45 PM · networkrpcsendmessageviewid

ViewID + Sending Messages

Hello,

Correct me if I'm wrong, but isn't a viewID the ID that the network gives to a gameObject to keep a reference of it?

I'm trying to get my Network.Instantiated projectile to send a damage message to who ever it hits, but I'm struggling to do that. So below is the script attached to my Projectile (arrow). What was happening is on CollisionEnter, if the hit is a player then hit.collider.SendMessageUpwards(damage), and then destroy the projectile... But no damage was never received.

So then I though I might need to use an RPC, so what I'm trying to do is use the vewID from the collider, and send a damage message:

 function OnCollisionEnter(hit : Collision){
 
    if(hit.collider.gameObject.tag == "Player"){
 
       var viewID = hit.collider.Network.viewID;
       networkView.RPC("SendDamage", RPCMode.All, viewID, damage);
     }
 Network.Destroy(GetComponent(NetworkView).viewID);
 }

 @RPC
 function SendDamage(viewID : NetworkViewID, damage : float){
 
    var enemyID = NetworkView.Find(viewID);
    var enemy = enemyID.observed.gameObject;
 
    enemy.gameObject.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
 }

But whats happening is that I get a NullException, at: var viewID = hit.collider.Network.viewID;

What do I need to do, to send damage to my collider object?

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
1
Best Answer

Answer by whydoidoit · May 24, 2012 at 11:21 PM

You need to be using:

  hit.collider.networkView.viewID
Comment
Add comment · Show 3 · 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 Bunny83 · May 24, 2012 at 11:43 PM 0
Share

Yes, like you guessed a ViewID connects the gameobject on different computers. The ViewID belongs to a NetworkView component. If you send the RPC with the networkview of your player, the gameobject that represents your player on the other computer will receive it.

Since you don't want to hurt yourself, you should send the RPC on the networkview of the object you want to hit.

avatar image oliver-jones · May 25, 2012 at 11:00 AM 0
Share

And to do that I change the RPC$$anonymous$$ode to Others, correct?

avatar image whydoidoit · May 25, 2012 at 11:03 AM 0
Share

Use Others only if you are processing the collision differently locally - use All if you want to receive the RPC on the object doing the sending too. This is normally easier.

I always like the "keep your code DRY" concept. (Dont Repeat Yourself). All allows you just to process the damage in an RPC call and not worry about the fact that you need to do something different on the sender.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to manage viewIDs? 1 Answer

RPC called with a viewID, reaching server with a different viewID 1 Answer

How to get a gameObject having viewID? 1 Answer

RPC call ending up on wrong target 1 Answer

PhotonView with ID has no method marked with the [PunRPC](C#) property! BUT IT HAS ??? 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