RPC Instantiate (basic question)

Options
Sandy
Sandy
Hi folks. Im kinda new using Photon Network. Until now i had 0 problems with Photon, but im kinda stucked now.

Im trying to make a Multiplayer Pong-like game. So when the players select their "ships" a ball will appear.
I think using a RPC for this new GO will be the best way to do it... so...



I did this in my update after a few conditions:

photonView.RPC ("BallSpawn", PhotonTargets.All, null);
In my RPC method:

[PunRPC] void BallSpawn(Vector3 pos,Quaternion rot) { GameObject a=Instantiate (ballObject,pos,rot ) as GameObject; }

And i get this error and the ball isnt spawning at all
NullReferenceException: Object reference not set to an instance of an object
BallSpawner.Update () (at Assets/MyScripts/BallSpawner.cs:36
PS: line 36 is my first code

This is not the properly forum for Question, moving the post. Sorry.

Comments

  • vadim
    Options
    Hi,

    You need to find out which reference is null. Probably you do not initialize it properly.

    Are you sure that ball should be plain GO? In PUN such things usually implemented as PhotonView objects and spawned with PhotonNetwork.InstantiateSceneObject (or PhotonNetwork.Instantiate if one of players owns the object). No RPC required in this case.