question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Notified when a specific SyncPrimitive changes

See original GitHub issue

I am trying to understand how to setup sharing, while setting up an exploratory test I was wondering something. From what I can tell, if a SyncPrimitive child changes in a SyncObejct, the ObjectChanged flag will be fired. But does that ObjectChanged flag tell you which particular SyncPrimitive Child changed? Or does it just say, “hey, there was a change in the children”? Which is the way I think it works. Is that correct?

So based on above, if I want to be notified of which particular SyncPrimitive Changed, I wrap SyncBool in a SyncObject wrapper. Like this:

[SyncDataClass]
public class SyncNotifyingBool : SyncObject
{
    [SyncData] public SyncBool IsActive;
}

Now I can be notified when individual SyncPrimitives Change in my SyncObejct class like:

[SyncDataClass]
public class SyncSpawnedTestContainer : SyncSpawnedObject
{
    [SyncData] public SyncNotifyingBool IsAActive;

    [SyncData] public SyncNotifyingBool IsBActive;

Is that generally the right idea overall?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Ristophonicscommented, Apr 24, 2018

@Firifire here is the most stripped down version. Please post any improvement. Regards

namespace HoloToolkit.Sharing
{

    public class BoolSynchronizer : MonoBehaviour
    {
        [SerializeField] public bool _thisToggle00;
        [SerializeField] public GameObject _GameobjectToToggle00;

        public SyncBool boolDataModel00;

        private void Start()
        {
            _thisToggle00 = false;
        }

        public void ToggleOffSwitch00()
        {
            if (_thisToggle00 == true)
            {
                Debug.Log("Toggling OFF");
                _thisToggle00 = false;
                boolDataModel00.Value = _thisToggle00;
                Debug.Log("Syncbool Value is NOW" + boolDataModel00.Value.ToString());
            }
        }

        public void ToggleOnSwitch00()
        {
            if (_thisToggle00 == false)
            {
                Debug.Log("Toggling ON");
                _thisToggle00 = true;
                boolDataModel00.Value = _thisToggle00;
                Debug.Log("Syncbool Value is NOW" + boolDataModel00.Value.ToString());
            }
        }

        private void CheckBoolStatus()
        {
            if (_thisToggle00 != boolDataModel00.Value)
            {
                _thisToggle00 = boolDataModel00.Value;
            }
        }

        private void FixedUpdate()
        {
            if (_thisToggle00)
            {
                _GameobjectToToggle00.SetActive(true);
            }
            if (!_thisToggle00)
            {
                _GameobjectToToggle00.SetActive(false);
            }
            CheckBoolStatus();
        }
    }
}
2reactions
Ristophonicscommented, Feb 9, 2018

Okay solved this issue by altering SyncSpawnedObject to inlcude a Syncbool.

/// <summary>
/// A SpawnedObject contains all the information needed for another device to spawn an object in the same location
/// as where it was originally created on this device.
/// </summary>
[SyncDataClass]
public class SyncSpawnedObject : SyncObject
{
    [SyncData] public SyncTransform Transform;

    [SyncData] public SyncString Name;

    [SyncData] public SyncString ParentPath;

    [SyncData] public SyncString ObjectPath;

    [SyncData] public SyncBool NetworkBoolean00; // new SyncBool

This Syncbool (the datamodel) is then initialized before instantiation in the PrefabSpawnmanager like so:

         // Add the data model object to the networked array, for networking and history purposes
        dataModel.Initialize(instanceName, parent.transform.GetFullPath("/"));
        dataModel.Transform.Position.Value = localPosition;
        dataModel.Transform.Rotation.Value = localRotation;
        dataModel.NetworkBoolean00.Value = false; // the new bool on SyncSpawnedObject

and at the same time the TransformSynchronizer is being added I also find my script on my prefab called BoolSynchronizer using the GetComponentInChildren AND set its boolDataModel to the same we created earlier on Spawn

        // Setup the transform synchronization
        TransformSynchronizer transformSynchronizer = instance.EnsureComponent<TransformSynchronizer>();
        transformSynchronizer.TransformDataModel = dataModel.Transform;
        BoolSynchronizer boolSynchronizer = instance.GetComponentInChildren<BoolSynchronizer>();
        if(boolSynchronizer != null)
        {
            boolSynchronizer.boolDataModel = dataModel.NetworkBoolean00;
        }

This is 90% the way there. The last 10% is writing your own BoolSynchronizer to do what you want with it and what happens when the variable changes. Took a few days of reading over the code again and again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Turn notifications on for list and list item changes
Stay up-to-date when lists or list items change by turning the Alert me setting on. Once turned on, you'll receive notifications with information...
Read more >
Create an alert to get notified when a file or folder changes ...
In the Alert me when items change dialog, select and change the options you want. To save, select OK. Get alerts on all...
Read more >
Get notified when a friend's location changes in Find My on ...
Get notified when a friend's location changes in Find My on iPhone. Use the Find My app to get a notification when your...
Read more >
Manage your notifications - Computer - Google Docs ...
Manage notifications for edits. On files in Google Docs and Sheets, you can change settings to get notifications when others make changes.
Read more >
Change notification settings on iPhone
In Settings on iPhone, choose which apps can send notifications, change the alert sound, allow government alerts, and more.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found