Static RPC

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on Fusion.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Static RPC

ykyrus
2022-05-18 05:24:28

From Docs :

** Remote Procedure Calls | Photon Engine **
Global cross platform multiplayer game backend as a service (SaaS, Cloud) for synchronous and asynchronous games and applications. SDKs are available for android, iOS, .NET., Mac OS, Unity 3D, Windows, Unreal Engine, HTML5 and others.

Now , I try to use static RPC ;

   public class TestRPC : SimulationBehaviour

  {

Start()

{

	Runner.AddSimulationBehaviour(this);

}	

public static void Rpc_MyStaticRpc(NetworkRunner runner, int a) { }

   }

When i run on editor , it give error :

"NullReferenceException: Object reference not set to an instance of an object

Fusion.NetworkRunner.AddSimulationBehaviour (Fusion.SimulationBehaviour behaviour, Fusion.NetworkObject obj)"

But in doc :

"can be used on a SimulationBehaviour, as the callback receiver is not bound to a particular NetworkObject. Note that any SimualtionBehaviour not associated with a NetworkObject will need to be attached to the NetworkRunner manually using Runner.AddSimulationBehaviour()"

As far as I understand, when using static RPC, there is no need to spawn any NetworkObject

Did I misunderstand something?

Comments

emotitron
2022-05-19 17:50:18

I don't see in your code above the [Rpc] attribute being applied to your RPC method? Be sure to include that or Fusion will not be aware of the method.

ykyrus
2022-05-20 07:27:08

Runner.AddSimulationBehaviour(this);

It give error ""NullReferenceException: Object reference not set to an instance of an object

Fusion.NetworkRunner.AddSimulationBehaviour (Fusion.SimulationBehaviour behaviour, Fusion.NetworkObject obj)"

If use instance RPC i only add Runner.AddCallback(this), this : object i will spawn on Network.

But if use Runner.AddSimulationBehaviour(); i dont know pass something for that ?

emotitron
2022-05-20 20:57:47

Ah, I follow now. The issue I am seeing there is that you are trying to use Runner.AddSimulationBehaviour... but that is a chicken/egg issue. To use Runner, this SimulationBehaviour already needs to have been added to the Runner (the SimB is not associated with a Runner until you have done this).

You might consider putting your class with the static RPC on the NetworkRunner prefab (that will find the SimulationBehaviour automatically), or you may want to bootstrap any SimB's from an INetworkRunnerCallbacks interface on your NetworkRunner prefab.

ykyrus
2022-05-21 14:31:25

Thanks for the reply,

But from your answer there are some things I don't understand:

"You might consider putting your class with the static RPC on the NetworkRunner prefab (that will find the SimulationBehaviour automatically)"

If I spawn a prefab with a class containing static RPC --> I will use instance RPC(Because in the document: don't need to spawn a network object containing this class)

"you may want to bootstrap any SimB's from an INetworkRunnerCallbacks interface on your NetworkRunner prefab"

I really don't understand. Could you give me an example?

emotitron
2022-05-23 07:24:21

I would just put your SimulationBehaviour with the static RPCs on your NetworkRunner prefab for simplicity here.

Back to top