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 Tsurugi21 · Jan 18, 2014 at 01:53 AM · functionrpcparameters

RPC won't accept valid parameters

Hi everyone,

im currently having a problem which block my path to the release of my game: While trying to execute this RPC

 @RPC
 function dmg (qte : float, target3 : playercore){
     target3.TakeDamage(Mathf.Round(qte));
 }

with the command

     if(Physics.Raycast(transform.position,avant,hit) && Time.fixedTime > tt + 0.1){
         if(hit.transform.GetComponent(playercore) != null){
             latestcore = hit.transform.GetComponent(playercore);
             core.DealDamage(1 * Bank.plcore.mgmult,latestcore);
             Debug.Log("gotplayercore");
         }
         tt = Time.fixedTime;
         Debug.Log("gotgameobject");
     }

to execute this function

 function DealDamage (amount : float, target : playercore) {
     if(networkView.isMine){
         networkView.RPC("dmg",RPCMode.All,amount * dmgmult,target);
     }
 }

but the game send me back

 Sending RPC failed because 'dmg' parameter 1 (playercore) is not supported.
 UnityEngine.NetworkView:RPC(String, RPCMode, Object[])
 playercore:DealDamage(Single, playercore) (at Assets/playercore.js:168)
 MachineGun_lan:Update() (at Assets/MachineGun_lan.js:35)

the latestcore var is a playercore type, why its not working? :( Thank you

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

Answer by asafsitner · Jan 18, 2014 at 08:23 AM

You cannot send your own types via `RPC`.
As written in the docs, the only valid parameter types for RPC are int, float, string, NetworkPlayer, NetworkViewID, Vector3 and Quaternion.
However, although not documented, an RPC can also receive a byte array, which bypasses the 4096 character limit on string parameters.

If you want to send your own custom type you'll have to serialize it into either a string format (think JSON/XML) or binary format, and parse it on the other end.

Comment
Add comment · Show 4 · 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 Tsurugi21 · Jan 18, 2014 at 02:44 PM 0
Share

Could I bypass this and retrieve the playercore component with a networkplayer?

And if I can't, how can I do this (If you want to send your own custom type you'll have to serialize it into either a string format (think JSON/X$$anonymous$$L) or binary format, and parse it on the other end.)

avatar image asafsitner · Jan 18, 2014 at 05:21 PM 0
Share

It's impossible to bypass this, it's the way RPC's are built.

For the simplest serialization solution you may want to take a look at the `XmlSerializer` class. Serialize to string, send it in the RPC and deserialize on the other end.

avatar image Tsurugi21 · Jan 18, 2014 at 05:25 PM 0
Share

Forget that, I kind of "Bypassed" this restriction with this:

 core.DealDamage(1 * Bank.plcore.mgmult,hit.transform.GetComponents(NetworkView);

new DealDamage function:

 function DealDamage (amount : float, target : NetworkView) {
     if(networkView.is$$anonymous$$ine){
         networkView.RPC("dmg",target.owner,amount * dmgmult);
     }
 }

and the RPC:

 @RPC
 function dmg (qte : float){
     Bank.plcore.TakeDamage($$anonymous$$athf.Round(qte));
 }

And it works perfectly ^^

avatar image asafsitner · Jan 18, 2014 at 09:19 PM 0
Share

Glad you figured out a solution. :)
If my answer did help you, I'd appreciate if you could mark it as answered so it won't appear in the questions queue.

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

19 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

Related Questions

boolean as function parameter/argument 2 Answers

Photon RPC "DestroyRpc" function not found 1 Answer

Function is being called even when not told to 2 Answers

How to make a game object of a certain class? 1 Answer

RPC parameters are "incorrect" - help 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