Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

New Input System with multiple Prefab

Discussion in 'Input System' started by RonanBouziane, Mar 19, 2020.

  1. RonanBouziane

    RonanBouziane

    Joined:
    Mar 19, 2020
    Posts:
    4
    Hello there,

    I'm using recently the New Input System and I have a problem.

    I don't know how i can add multiple Prefab to the PlayerInputManager.

    For the moment i can use 2 different controller to controll 2 different player but they have the same prefab.

    PlayerControls.png

    PlayerInputManager.png

    PlayerInput.png

    I have looked for a solution but i didn't find any explicit example.

    If someone could help me I would be very grateful.

    Thank you for your time.
     
  2. zenmasterchris

    zenmasterchris

    Joined:
    Mar 17, 2015
    Posts:
    3
    I'm having this issue as well. Did you figure this out?
     
  3. MrBob31

    MrBob31

    Joined:
    Mar 23, 2019
    Posts:
    1
    I hope i can help you.

    This is my Solution for this Problem.

    Make a Reference to the PlayerInputManager and the Prefab for Player B and when you initialize Player A you can change the Prefab in the PlayerInputManager.

    Sorry for my bad english.

    Here ist an example code

    Code (CSharp):
    1.  
    2.  
    3. public PlayerInputManager inputManager;
    4. public GameObject playerA;
    5. public GameObject playerB;
    6. public GameObject playerPrefabB;
    7.  
    8. void OnPlayerJoined(PlayerInput input)
    9.     {  
    10.         if (playerA == null)
    11.         {
    12.             playerA = input.gameObject;
    13.             inputManager.playerPrefab = playerPrefabB;          
    14.         } else
    15.         {
    16.             playerB = input.gameObject;          
    17.         }      
    18.     }
     
  4. RonanBouziane

    RonanBouziane

    Joined:
    Mar 19, 2020
    Posts:
    4
    Hello,

    Yes I solved my problem, thanks to this video :


    I hope this help.
     
  5. Raptosauru5

    Raptosauru5

    Joined:
    Feb 8, 2019
    Posts:
    24
    Video is unavailable. Can you please describe what happens or share a name of the video?
     
  6. JimmayJamez

    JimmayJamez

    Joined:
    Jul 29, 2022
    Posts:
    1
    Heres my system.
    I checked if a gameobject (the previous player prefab) with a tag (in this case my original prefab was tagged with Player 2), had spwaned in, then it would access the input manager's prefab and change it.


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.InputSystem;

    //PLACE ON PLAYER MANAGER OBJECT
    public class InputManagerController : MonoBehaviour
    {
    [SerializeField] private GameObject newPlayerPrefab; // The new Player Prefab to use.

    public PlayerInputManager inputManager;

    private void Update()
    {
    if (GameObject.FindWithTag("Player2")) //Checking for a game object with the tag
    {
    PlayerInputManager.instance.playerPrefab = newPlayerPrefab; //If yes, changes the player prefab field to your selected prefab
    }
    }
    }