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 thecompactor · Jul 13, 2017 at 06:07 AM · androidnetworkingmultiplayerbooleansynchronization

Easiest way to sync a boolean variable across multiple Android app instances?

I'm working on an Android app for learning purposes. In particular, I'd like to learn the best method to sync a boolean state between multiple instances of this app running on separate devices.

What exactly is my app so far? The app is called Coin Flip. You can download the project here on DropCanvas. It simply has an image of a coin heads-up, over a white background. Tap on it, and it will change to be tails-up (a different sprite). Tap again, and it will go back to heads. It always alternates to the other face when tapped. Clearly this is a basic demonstration of a toggle-able boolean state.

Let's say I build my app to my brother's Android, as well as my own. What I'd like to happen is have his coin's facing stay in sync with my coin's facing, such that we are flipping the same coin. Ideally, at least 16 people could all have the app installed and we'd all be in sync when connected to the internet, flipping the same virtual coin.

I've done some research into Unity's multiplayer possibilities, and I have to say I'm a bit overwhelmed. The Unity HLAPI (High Level API) seems focused on player GameObjects and only synchronizing those in particular. I've also seen the Photon plugin. Then there's the possibility of using a database such as through Azure, AWS, Redis... but I haven't done that before and I'd like to stay within Unity functionalities – and stay free – if at all possible.

Considering that in the future my actual app (since this is just a proof of concept) might contain a 100 by 100 grid of "coins", I would probably need to synchronize a 2-dimensional array of booleans.

So my question is, what route would you recommend for this multiplayer scenario? And does the recommendation change when considering 100x100 coins instead of a single coin?

Issues I predict are:

• how to handle latency between flips – players could end up physically tapping at the same time, while virtually they see opposite coin sides

• how to deal with players trying to flip when they aren't connected to the internet

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by EdwinChua · Jul 13, 2017 at 06:21 AM

@thecompactor You could look into MQTT. The protocol is lightweight, and uses a publish-subscribe model to push data to subscribed devices.

You will, however, need to run your own MQTT server, and come up with some security measures (if you so require).

I am currently running an MQTT server at http://www.crazy.technology/ which you can use at your own risk. (Traffic not monitored nor regulated. No guaranteed uptime as well.)

Links to get you started:

1) MQTT - An overview

2) MQTT broker (Server) download

3) Sample Project (Not mine)

4) M2MQTT library

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
avatar image
0

Answer by Hunter_Bobeck · Jul 14, 2017 at 08:01 AM

I've found a working solution via Firebase. Learn how to integrate it into your Unity project here.

Here's the content of the JSON I used for the database (I toggle the single boolean value between true and false):

{ "flippage":true }

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

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

182 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

Related Questions

Help| Sync' boolean variable (Friendly Fire) 0 Answers

Unity networking tutorial? 6 Answers

Multiplayer - Parent's children not syncing 0 Answers

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

UNET : SyncVar value not updating, hooks firing 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