- Home /
RPC isn't called on objects with another name, even though they have the same script.
Hello
I have an object that has a script. The script calls a remote procedure call on itself, but only on object where the name hasn't been modified. How can I fix this?
Thanks in advance.
All of the examples below are in the same script.
void Update()
{
//Let's send RPC calls to all the other players.
networkView.RPC("DoSomething", RPCMode.Others);
}
//This is supposed to be called on all objects with this script.
[RPC]
void DoSomething()
{
//This only gets called on objects with the default name, and not on objects with modified names.
Debug.Log("Prefab is doing something!");
}
NOTE: All of this is in one script, but it doesn't get called on objects that don't have the default name.
Please share some code, it's very hard to help without knowing the full problam
I just gave you the full problem. I have one script that sends RPCs to all other players (it is still the same script), but it only sends to the objects with the original name (prefab name in the assets). It doesn't send to the same object if it has another name than the original prefab name.
Just describing it is not enough.
Show the code that sends the RPCs (for example).
We can't find the problem if we can't see it.
The thing is, that the RPCs work flawlessly, but only if the instantiated prefab has the same name as it had when it was instantiated. If I change the name, alternatively the tag, it won't receive the RPC.
If you keep reasoning why you don't need to show code, then I can't help you, sorry.
Answer by dorpeleg · Mar 23, 2013 at 07:31 PM
In the description: A NetworkView must be attached to the GameObject where the RPC function is being called.
Do you have a NetworkView attached?
In the description: if two RPC functions in different scripts have the same name only one of them is called when RPC is invoked.
Maybe that's the problem.
You might also want to try changing the RPCMode and see if it makes any diffrence.
I have a NetworkView attached to the objects, and I am only using one script for this. Though, I have attached the script to multiple objects, but I everything is in one class, one namespace, one script. I've always had one script, because I can't send remote procedure calls to another script. That is why I placed all the RPC sender and RPC receivers in one script. Even though I did this, it doesn't work.
As you said: " //This is supposed to be called on all objects with this script."
It means you have more then one script. (even if its the same one)
So your problem is:
if two RPC functions in different scripts have the same name only one of them is called when RPC is invoked.
"This is supposed to be called on all objects with THIS SCRIPT" - This means this script only. I only have ONE script. It doesn't communicate with itself, and that is the problem.
I Don't think you understand.
"all OBJECTS with THIS SCRIPT"
That means each object has another copy of the script (even if it is the same) and that is why only one RPC is called.
Yes, they have another copy of the script, but when you call a remote procedure call it is sent to all instances of the script (class). All objects have the same script and the same class, therefor it should be called on all the objects with this script.
Let's say I call "DoSomething" to all players. Then the "[RPC] void DoSomething()" should be activated on all copies of the script, on all players. In my case, it only gets activated on objects with the name/tag it had in the assets.
The objects have NetworkViews attached, and everything else that make them function properly.
By the way... If what you're saying is true, why can I send the message to the objects with default name/tag (they also have copies of the script, just like the renamed objects)?
Your answer
Follow this Question
Related Questions
Multiplayer Chat Script (Problem : mixed names) 1 Answer
problem with raycasts and tags 1 Answer
RPC call ending up on wrong target 1 Answer
RPC setName() not working correctly 0 Answers
supplied parameters doesn't match the rpc declaration 1 Answer