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 galhajaj · Oct 03, 2017 at 03:47 AM · networkingnetworkclient-server

Network - Sync a seed random number at the start of the game

Hello, I have a simple network game - two cars (one server the other is client) and a random generated environment. for the latter to be equal in both of the instances of the game I need to generate random seed at the server and then pass it to the clients at the start of the game. How can I do that?

I tried:

[SyncVar] int randomSeed;

void Start() { CmdGenerateNumber(); }

[Command] void CmdGenerateNumber() { randomNumber = Random... RpcDoOnClients(); }

[ClientRpc] { Generate level by the seed... }

I guess the problem with that solution is that I don't send to another client in time... the server make the calculation and then send only to itself (as a client) How can I verify the existence of the two cars and only then activate the sequence of generating in server and then send to clients? Thanks :-)

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by yanivng · Oct 03, 2017 at 07:26 AM

You can generate a GUID (System.Guid.NewGuid()), send it to both the clients and use it as a seed to the random generator you are using. Game will start running in the client only after the start message (carrying the seed) has arrived. Let me know if that helps, or if you need more information.

Comment
Add comment · Show 5 · 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
avatar image galhajaj · Oct 03, 2017 at 12:58 PM 0
Share

Hi Yaniv, Where the guid should generated? inside the server? I didn't understand that line - "Game will start running in the client only after the start message (carrying the seed) has arrived". thanks!

avatar image galhajaj · Oct 03, 2017 at 01:08 PM 0
Share

And thanks but my problem is not the random seed... the problem is where to generate it and when to publish it to all clients.

avatar image yanivng · Oct 03, 2017 at 01:26 PM 0
Share

Can you please elaborate: how does the server communicate with the clients? Do the game start in a client without contacting the server first?

avatar image galhajaj yanivng · Oct 03, 2017 at 01:46 PM 0
Share

Hi, I'm using the standard networking library. the game starts (go to the playing scene) after 2 players joining - one as the host & server and the other as the client

avatar image yanivng galhajaj · Oct 03, 2017 at 05:17 PM 0
Share

In this case, the client must wait for a message from the server containing the seed, and only then start the actual logic which is randomly generated

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

118 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

Related Questions

Since switching to using offline & online scenes in the NetworkManager, Clients will not sync (UNET) 0 Answers

[Unet] NetworkServer can not assign local player authority after a scene change 0 Answers

Network command is running on client? 1 Answer

NetworkBehaviour.isClient problems 1 Answer

.io style matchmaking (one button matchmaking) 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