- Home /
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
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.
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.)
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.
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 ^^
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
![](https://koobas.hobune.stream/wayback/20220613130735im_/https://answers.unity.com/themes/thub/images/avi.jpg)