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! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

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

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.

How can I find and access Local player components using PUN2 in Unity?

BHS
2023-02-14 18:40:26

Hello,

I have 2 scripts 1: Player and 2: Game Manager, both spawn when the game starts.

Since each player will be spawning the same 2 objects (player and game manager) when the game starts... How can I get the local Player script on Game Manager Start function?

I tried this method:

But it sometimes works and sometimes returns Null Reference error and breaks my game.

Comments

Tobias
2023-02-17 14:58:16

Those scripts are both part of a prefab with a PhotonView on it?

Each script can refer to the PhotonView on the same GO to figure out if IsMine is true.

BHS
2023-02-17 15:24:02

Tobias 2023-02-17T14:58:16+00:00

Those scripts are both part of a prefab with a PhotonView on it?

Each script can refer to the PhotonView on the same GO to figure out if IsMine is true.

No, They are not part of the same prefab, My Spawner script instantiates both the Player prefab and Game Manager prefab (both has their own Photon Views) when the game starts.

Back to top