Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 LivingUniverse · Jan 24, 2017 at 05:19 AM · networkingmultiplayerphotonspawn

Spawn players in unique places (Photon networking) Object sync problem for entering players.

(Also posted in photon forum, but i need an answer !!!) Ok i give up...thats why im posting this. I just cant figure out why my variables arent updating.

Currently this is how i am spawning the player:

spawnPoints = GameObject.FindGameObjectsWithTag("pSpawnP"); bool spawned = false; while(!spawned){ int randS = Random.Range(0, spawnPoints.Length); if(spawnPoints[randS].transform.childCount == 0){ GameObject insPlr = PhotonNetwork.Instantiate(playerPrefabE[selectedModel].name, spawnPoints[randS].transform.position, spawnPoints[randS].transform.rotation, 0); insPlr.transform.SetParent(spawnPoints[randS].transform); spawned = true; }else{ spawned = false; } }

In my scene i have spawn points with photon views. When i spawn my player i check if a spawn point has a child and if it doesnt i spawn it and set that spawn point as the parent to my player. However when other players join they cant see that i am a child of the spawn point. The spawn point isnt synchronizing its children.

I also tried making a script for the spawn points and setting a bool to false. When i spawn the player i check if its false and then spawn the player and set it to true. I set this variable using a PUNRPC call, but when other players join the game they cant see the updated variable. I tried using an int and setting it to 0 when not occupied and 1 when occupied but when players enter they cant see it update. I also tried putting the variable in PhotonOnserializeView and i tried different observe options and still when players enter the match they cant see the updated variable, just the default.

Am i missing something? How do i sync a variable for players that havent joined the match yet, or how can i sync a spawnpoint and the child object to new players entering the match.

thank you, chris

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 LivingUniverse · Jan 22, 2017 at 05:36 PM 0
Share

okokokokokok i found out a few things after testing the occupied variables. if i set them with rpc actually do sync to players that enter however this is where it gets super tricky. When the player spawns in the game i use an rpc called spawn player when new players spawn they run the rpc because the rpc is buffered for all new players. They spawn in faster than the variable occupied gets synced up. I debugged the variables occupied at the time the player spawns in and they come out all false, but wait some milliseconds later and the ones occupied debugged out as true so i put in a spawn button to try the spawn the players when they want. If the first person connects his network manager gets updated, the other players that come in their manager doesnt get updated and they cant spawn. If the player that created the room which is the masterclient leaves instantly the other player gets his network manager updated and he can spawn in i cant believe how frustrating this is. If i cast rpc they spawn in faster than the variables are synced and i cant seem to delay the rpc like a second or something and if i dont use an rpc the network managers for other players dont get updated some reason.

I think if i am able to delay the buffered rpc for new players for like a second it will work. How do i delay it??

avatar image LivingUniverse · Jan 22, 2017 at 11:00 PM 0
Share

I finally came up with a solution that works after many many hours...

spawn the player in using a random number generator 2000 - 3000 pos x y and z, 1 out of a trillion chance the players are going to have the same pos... or you can just turn mesh off, use a smaller number and turn it on in the next step: I added a spawn/ready up button and since the player is spawned the spawnpoint variables that were already set had time to be synced and then when you press the button it searches the spawnpoints, finds a free one and then i use two rpc calls, 1 that sends the view id of the player gameobject to the spawnpoint and search for the gameobject according to the view id and then turn bool occupied to true. In the update i have if(occupied && occupant != null) run and rpc to turn occupied to false. So if players leave it frees up the spawn point. The spawn/ready up button also sends an rpc notifying all players that the player is ready, when all players are spawned and ready the match begins.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Photon - Loads a level but doesn't spawn player. 1 Answer

Unity networking tutorial? 6 Answers

Problems/Errors With Photon Conversion.. [ScreenShot] 0 Answers

How to Serialize Playermovement when Player jitters? 0 Answers

What's the best method to implement multiplayer on a Billiard game ? 1 Answer


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