Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 /
This question was closed Oct 11, 2015 at 02:53 PM by Namaarie for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Namaarie · Aug 05, 2015 at 03:03 AM · photoncyclenightday

Photon Day Night Cycle Unsynced

Soooo, basically I have a survival game where there is a day night cycle, but since the start of the day is hard-coded by setting the time, when you join a server that has a different time and the default starting time, the time won't be synced when playing in a server. And I need help on how to sync it across the server. I have tried Googling it, but whenever someone tries to answer, they just give VERY unspecific answers, with no explanation on how to actually accomplish this.

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 tobiass · Aug 05, 2015 at 08:06 AM 1
Share

You need to clarify what you want to achieve and why it fails. I tried but I don't get it: "since the start of the day is hard-coded by setting the time, when you join a server that has a different time and the default starting time, the time won't be synced when playing in a server."

What is hardcoded? Where? Server?

Built in to Photon, there is only the server timestamp. That is not a datetime value. It's just how long the server runs. This is good enough to sync stuff in a room.

If you need a datetime (5. Aug. 2015 10:16), you need to send this from the server or somewhere. You need a reference.

avatar image stepan-stulov · Aug 05, 2015 at 09:01 AM 0
Share

Plus one to the previous comment. You have to decide whether you're asking for a general explanation of client-server authority distribution architecture, or to "give you them codez".

In case of the first here is a good starter article:

http://gafferongames.com/networking-for-game-programmers/what-every-programmer-needs-to-know-about-game-networking/

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by 334499p · Aug 15, 2015 at 07:41 AM

You're going to want the day/night cycle to be controlled by a float variable. The basic idea of syncing the cycle is that when you are connected to a room, the master client gives you its cycle float value every frame and then you adjust your cycle according to that variable. For example night could be represented as 5 and day could be represented as 10 clamped to 0 (if it goes past 10 then it goes back to 0). So say its night time in the server that you join: When you join the master client will give you a value of 5 and then you change your cycle. So for the actual code:

Your going to need to edit your cycle script and the gameObject on which it is placed. On its gameObject add a PhotonView and then add this to the script after the Update function add:

 [RPC]
 void getTime(float time){
 //Change your cycle according to the received time
 }

In the Update() function for your day/night cycle script add:

 if(PhotonNetwork.isMasterClient){
 GetComponent<PhotonView>().RPC("getTime", PhotonTargets.Others, time);
 }

The above RPC is received by ALL players EVERY frame so that if you change the time for yourself then EVERY player's day/night cycle is adjusted immediately. If you don't care about updating the cycle every frame then you could be the second part of the script (the rpc call) on a timer so that it only calls every 10 seconds or so. If you do that then you will need to lerp the cycle for each non-Master-Client so that it looks smooth.

Comment
Add comment · Share
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

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Blend two lightmaps for day/night cycle? (terrain) 0 Answers

Object rotation shifting 1 Answer

Day Night Cycle Script Not Working 3 Answers

Day/Nights cycle 2 Answers

Day Night cycle question 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