Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Joining Enabled by default causing error with instantiating objects

Discussion in 'Input System' started by TubbyStubby, May 17, 2020.

  1. TubbyStubby

    TubbyStubby

    Joined:
    Nov 28, 2019
    Posts:
    6
    I am trying to make a local multiplayer and using Joining Enabled by Default in Player Input Manager.
    I instantiate a bullet OnShoot when left mouse button is clicked.
    for some reason I get two instances of the bullet one is correct and extra which spawns at zero all the time no matter where the player is currently.
    Annotation 2020-05-17 154710.png
    I am checking for the started, performed and canceled stages so its not happening because of events.

    public void OnShoot(InputAction.CallbackContext ctx)
    {
    if(ctx.performed)
    Instantiate(ammoPrefab, transform.GetChild(1).position, transform.GetChild(1).rotation);
    }

    When I disable Default joining and add the player my self to scene it doesn't spawn any extra bullet.

    EDIT - I found a work around. I made a boolean and set it true in Awake() and then I check if this value is true before shooting. Don't know why I have to do this but seems to work for now without any problem.
     
    Last edited: May 17, 2020