SimulateOwner - GetKeyDown and GetButtonDown multiple events

Options
I'm having a problem where Input events are raised multiple times in SimulateOwner. For example, the code:

public override void SimulateOwner() { if (Input.GetKeyDown(KeyCode.F)) { var flash = FlashColorEvent.Create(entity); flash.FlashColor = Color.red; flash.Send(); Debug.Log("simulate owner - " + Time.time); } }

If I run the project and press F one time, the GetKeyDown event happens twice:


The same problem happens with GetButtonDown and GetMouseButtonDown. If I move the Input code into Update instead of SimulateOwner I do not get multiple events.

Comments

  • stanchion
    Options
    SimulateOwner is done in FixedUpdate, you should take input in Update like PlayerController.cs
  • Vatara
    Options
    Oh, that's confusing, because the tutorial shows the Input in SimulateOwner. Since I only want the input to run on the client I suppose I need to wrap it in an entity.isControllerOrOwner check?
  • stanchion
    Options
    Yes, except only controller, not controller or owner
  • mattm
    Options
    You can still do your logic in SimulateController if you want. Just poll the keys in update, set a boolean if KeyDown to true and set this back to false at the end of SimulateController.
  • laurel
    Options
    I don't know if I should post it here but I have a similar problem.
    When I press "P" I want to send an event.
    And my event is received twice.
    Raising [RangeWeaponAttackEvent playerEntity=[Entity [NetworkId 0-0-0-1-0-0-0-1] PlayerCharacterState]] // twice in the debug log.

    On the server it's fine, that happens on the client.

    I have in SimulateController this;
    isShooting = Input.GetKeyDown(KeyCode.P);
    and
    input.Shooting = isShooting;

    I have in ExecuteCommand this:
    if (cmd.IsFirstExecution)
    {
    PlayerAttack(cmd);
    }

    In my PlayerAttack Method I have:
    if (cmd.Input.Shooting)
    {
    FireProjectile(cmd);
    }

    If I use a debug.log info, everything is sent once (in the previous bits of code).

    But in my GlobalEventListener I receive the event twice

    public override void OnEvent(RangeWeaponAttackEvent evnt)
    {
    Debug.Log("Fire Projectile"); // shows up twice
    }

    This is the event that is used to send it to the server (called once from the PlayerAttack())
    void FireProjectile(PlayerCharacterCommand cmd) {
    RangeWeaponAttackEvent eventProjectile = RangeWeaponAttackEvent.Create(Bolt.GlobalTargets.OnlyServer);
    eventProjectile.playerEntity = entity;
    eventProjectile.Send();
    }
  • laurel
    Options
    I fixed it by using entity.hasControl. But it's weird, because the intellisense was not giving me the "hasControl". Anyway. I make sure I only send the event if I'm the controller.