Event to indicate client is synchronized with sim

Is there an event or something similar we can hook into to know when client has fully processed network state and is considered in sync (until the next frame starts processing)?

The reason I am asking this is I have known for a long time that, say you create 10 objects on Sim in one frame, client will not receive those 10 objects in the same order they were created.

This is an issue when using synced GameObjects because if one networked object references another, if the client has not yet received/processed the referenced object, it will at time of instantiation, be a null reference.

If you have code that wants to do something on networked instantiation with that networked reference, which is null, it will obviously error out. The only reliable solution is to wait for all objects to be instantiated and synced before doing any sort of initialization functions that involve referencing other objects.

Please advise if there is any such functionality that can help alleviate the issue that arises from this.

Hi Neodamus!

Have you tried registering a listener on the CoherenceBridge.OnLiveQuerySynced event? I think it might be what you’re looking for.

1 Like

Thank you for the quick response @miguel-coherence :smile:

I tested that event out, and it does not look like it solves my issue.

It looks like OnLiveQuerySynced runs only once on initial connection, which definitely is useful. But…

It looks like if a batch of multiple objects is created after this point, this event will not fire. Is that correct? Because I need such an event in my case.

I see that there is a NetworkEntityCreated event as well, but what I really need is something that is, if any number of network entities are created, invoke OnLiveQuerySynced when they’re all synced and ready.

In other words, I will need this event to fire multiple times and not just once over a game’s lifetime, as I will be creating batches of networked objects at multiple indefinite times depending on how the player interacts with the game.

Is something like this built in?

I don’t think what you’re describing is possible to do from our side, we have no way of referencing a batch of entities in the manner you’re describing, for us every entity is independant from each other.

Like you mentioned, we have a callback for network entity creations, so perhaps you can do some custom logic by adding a custom identifier to the batch of entities you wish to synchronize and then fire an event based on this custom identifier that will effectively ID a batch of entities.

I’ve already got a custom system for handling this, I’m just about to improve it because its not very scalable.

I do think it is doable on your side because the batch I’m talking about basically just needs to be “any object created during this network update”.

When client syncs, obviously there is already some way of knowing if an object was created in this update (this is already exposed)

All I’m saying is, once all the objects have been created that are going to be created for this network update, trigger an event that basically says “Objects were created in this network update, and they are now ALL ready to be used”.

This could be something done at the very end of a network update. It could check whether objects were created in this update, and if there was at least 1 object created, the event would fire.

I think the real question is… is that going to be a general use case and worth implementing on your side?

I’d say anyone that uses synced GameObject properties is going to want this to ensure that those references are valid before they try to perform some logic on those references.

I’d also say that any game that has complex network objects is going to inherently use synced GameObject references because of the way Coherence is designed.

One basic example of this is a unit with abilities. If both unit and ability are network objects themselves, there will need to be a reference made one way or another to keep track of the relationship.

If a unit is created with multiple abilities, the sim will create them all in the same frame, and it will be able to easily make those relational references at instantiation.

However, on client, the unit and abilities will instantiate in basically random order, and will not all be available at once. If the unit object is created on client first, and abilities have yet to be created, I can’t run an initialization that involves references to the abilities, or it will fail.

I have to wait until I know both units and abilities are created and can properly reference each other before I can attempt to rely on those references at all.

This is what I do custom currently, but I just wanted to at least ask before I reworked what I had.

1 Like

There is no such concept as a “network update” , if you create 20 entities in a single frame in the simulator there is no guarantee that all 20 entities will be received by every client in the same frame.

1 Like

Ah ok, I understand. I’ll just keep doing it as I have been then. Appreciate all your insight on this, it’s helped me to better understand what’s actually happening :smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.