Comparing NetworkID dont work correct

Options
hi, i want to subtract health from the enemy entity via events. when i hit the entity i dont get the player to loose health cause the networkID is not same. i get the entity script with raycast from the enemy then i pass the network id to a variable and send it in a event . in the onEvent method they should compare the received networkID and execute the getDamage method if its the same. global sender is only client and entity sender only owner . i use this scripts for that


public class Weapon_Bolt : MonoBehaviour
......
RaycastHit hit;

if (Physics.Raycast(ray, out hit, weaponStats.maxRange, layerMask, QueryTriggerInteraction.Ignore))
{
Debug.DrawRay(ray.origin, ray.direction * 500, Color.red, 0.1f);
if (hit.collider.GetComponentInParent<PlayerStats>())
{
PlayerStats stats = hit.collider.GetComponentInParent<PlayerStats>();
NetworkId id = stats.entity.NetworkId;
playerCallback.GiveDamage(id, 10);
}
}....

public class PlayerCallback : EntityEventListener<IOnline_PlayerState>
......

public override void OnEvent(DamageEvent evnt)
{
Debug.LogWarning("Event Received by owner" + evnt.ID + "left hit and right owner" + entity.NetworkId);
if(evnt.ID == entity.NetworkId)
{
Debug.LogWarning("EVENT is same");
playerStats.TakeDamage(evnt.Health);
}
}

public void GiveDamage(NetworkId id , int damage)
{
DamageEvent evnt = DamageEvent.Create(entity, EntityTargets.Everyone);
evnt.Health = damage;
evnt.ID = id;
evnt.Send();
}

Comments

  • stanchion
    Options
    With an entity event there is no need to do a networkid compare, the event is only sent to that entity. If there seems to be an issue with networkId comparison send us a full repro and we can investigate, I would double check whether the encapsulated GUID is different on these different clients as entities should have the same networkId across the network.
  • ah ok thx for the answer now its more clear to understand for me. The network ID is not wrong first i though it cause in the DebugLog i got two different NetworkIDs but i think that the log is not comming from the owner in the editor its came from the same entity who send this evnt, i think that was the reason for the two different IDs. i testet it with debug.Log under if(entity.IsOwner) and then nobody got the message. sry for my low english knowlegde. But one thing i try to understand if i send a entity event to an specific entity, how the event know who i mean ? cause every player has the same PlayerState entity. When i hit someone other than me than every player exept me get the event and take damage or not ? cause i set entityTarget.EveryoneExeptControllerAndOwner.
  • GanjaRaiders52
    edited December 2020
    Options
    Or is here any way to modify the Health state from a other entity as client ? the method with AddCallback like in the only 2 videos i watched does not work for me. I see some people use events but i find out how they do it? Should i use Global events to get it work maybe ?

    Edit: With globalevents i get it to work with comparing the network ID finally i get it to work, i think. when i throw a look at the state behaviour from both player the states update correct and the correct entity which i hit loose health. but i still get the log message only owner can modify the state "Health". but this is not bad so long as t works.