Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DaveA · Apr 01, 2021 at 08:49 PM · networkingplayerphotoninstantiate prefab

Photon player instantiation BY MAGIC!?

I've got a little game I'm building, using the Photon Asteroid example as a model. that is, it has a 'lobby' where players gather, then enter the main scene. When I load the main scene I instantiate player avatars. I must be doing something wrong, but it's spooky what happens:

             Player[] sorted = PhotonNetwork.PlayerList.OrderBy((p) => p.ActorNumber).ToArray();
             Debug.Log(sorted.Length + " users in room");
             foreach (Player p in sorted)
             {
                 Debug.Log(string.Format("{0} {1}: is local {2}, is masterclient {3}, ", p.NickName, p.UserId, p.IsLocal, p.IsMasterClient));
 
                 if (p.IsLocal)
                 {
                     GameObject go = PhotonNetwork.Instantiate(playerPrefab.name, Camera.main.transform.position, Quaternion.identity, 0);
                     go.transform.parent = Camera.main.transform;
                     go.name = p.NickName;
                     go.SendMessage("SetAvatarName", p.NickName); ;
                 }
             }

I'm assuming I'm only going to instantiate my avatar when it's 'local' (that's 'me' right?). In fact, I maybe don't even need to see 'me' so I could avoid this?

Well here's the spooky part. If I join one player from remote, I have 2 players when I enter this scene. One isLocal, the other is not. So, only ONE (the local one) should be created, yes? BUT TWO are created. And I cannot figure out where it's coming from. This is the only place in the game I reference playerPrefab, and it's in my class (unless it's hiding a same-named object in a base class???) Anyway, the code that sets the name and avatar label does NOT get executed on the remote user. Everything else about the remote player works fine, I can see him moving properly about the scene.

Any insights welcome.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image purpl3grape · Apr 02, 2021 at 09:52 AM 0
Share

What do you mean 2 are created? Is it 2 characters spawning per photon player, so 4 in total?

Because as I read the code, there are 2 photon players in the game, and each spawns a player of their own, making 2 gamer characters in the scene.

avatar image andzq · Apr 02, 2021 at 12:06 PM 1
Share

If you create a character via photonNetwork.Instantiate, it is a synched object that will be created for everyone that is in the same photon room. As stated by purpl3grape, seeing two character objects is the expected behavior of this code snippet. The masterclient enters the room and creates a character via photonnetwork. This character will be created for everyone that is in the room (and joins later). When the second player joins he will also create a character object that will be synched for everyone in the room. So you got one synched character for each player.

As said. The local character you see is created by this script. The remote (non-local) character is the copy, that photonNetwork will create for all other players in the room.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

189 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to manually destory GameObjects on player leaving game in Photon 1 Answer

Photon Network, how to spawn FPSController from Unity Standard Assets? 2 Answers

[Photon] Getting the players in a room in the same order 1 Answer

PhotonNetwork.Instantiate is not "buffered" 0 Answers

Player names all displayed as local player photon 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges