ainesh1998
ainesh1998

Reputation: 11

Photon Bolt: Inconsistent Network IDs across Network

I have two clients, A and B, both implementing Bolt.EntityEventListener

When I print out the networks ids of A and B with A being the owner, I see the following mapping:

A => network_id [1]

B => network_id [2]

However:

When I print out the networks though B's view, the networks ids are swapped:

A => network_id [2]

B => network_id [1]

I was under the impression that network ids are consistent and unique across the entire network. This doesn't seem to be the case.

How do I uniquely identify a given entity across the entire network?

Upvotes: 1

Views: 308

Answers (2)

DirtyFred
DirtyFred

Reputation: 5

What you can also do is add to the Bolt State asset a property with type Entity called Parent.

Instantiate the GameObject as a server:

 GameObject newCamp = BoltNetwork.Instantiate(campPrefab, campPos.position, Quaternion.identity);
            newCamp.GetComponent<CampController>().state.Parent = campPos.GetComponent<BoltEntity>();

And this is the code on the GameObject itself

 public override void Attached()
{
    state.SetTransforms(state.BoltTransform, transform);
    state.AddCallback("Parent", ParentCallback);
}

private void ParentCallback()
{
    transform.SetParent(state.Parent.transform);
}

This code is copy pasted from my project so it works 100%.

I hope i could help

Upvotes: 1

Michael Urvan
Michael Urvan

Reputation: 547

1: You shouldn't need unique IDs, if you do it's better to use your own system via ScriptableObjects with an Id field.

2: By identifying you probably mean that you want to identify it so you can act on objects of other clients for the same replicated gameobject, and you can do this by passing an Entity type as a parameter in an Event. When you send the event, you just set that parameter to be the GetComponent<BoltEntity>() on the gameobject, and Bolt will handle resolving the parameter so anyone receiving the Event will have that Entity parameter pointing to the same one that corresponds to the replicated object/Entity that you sent from another client.

3: To Summarize: in the Bolt Assets window, add a parameter in your Event of type Entity. So for instance int DamageAmount and Entity TargetCharacter In code, use the A.GetComponent() when sending the Event. MyDamageEvent.Post(10, A.GetComponent()); if your Event had two parameters, an integer damage amount and an Entity parameter. In the overriden OnEvent() in your BoltEntityEventListener child class you will automatically have the BoltEntity there. So you can do ev.TargetCharacter.gameObject and do whatever you need.

Upvotes: 0

Related Questions