Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved [SerializeField] private InputField Cannot drag button.

Discussion in 'Scripting' started by RubenVanOostveen, Feb 23, 2021.

  1. RubenVanOostveen

    RubenVanOostveen

    Joined:
    Jul 31, 2020
    Posts:
    91
    unity version: 2020.2.0a11.1312.3 (i dont wanna upgrade because i use coleberate and maybe old scrips wont work)

    Iam following this tutoiral:



    At 6:15 she/he drags in an item into the inspector.
    but when I try it I get an stop sign:



    Ive tried making it objects/making public looking at other forum post and tried them all. Help would be appreciated. (also tried switching from TMP to regular and that only worked for "Username Input")

    CODE:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class MenuController : MonoBehaviour
    7. {
    8.     [SerializeField] private string VersioName = "0.1";
    9.     [SerializeField] private GameObject UsernameMenu;
    10.     [SerializeField] private GameObject ConnectPanel;
    11.  
    12.     [SerializeField] private InputField UsernameInput;
    13.     [SerializeField] private InputField CreateGameInput;
    14.     [SerializeField] private InputField JoinGameInput;
    15.  
    16.     [SerializeField] private GameObject StartButton;
    17.     private void Awake()
    18.     {
    19.         PhotonNetwork.ConnectUsingSettings(VersioName);
    20.     }
    21.  
    22.     private void Start()
    23.     {
    24.         UsernameMenu.SetActive(true);
    25.     }
    26.     private void OnConnectedToMaster()
    27.     {
    28.         PhotonNetwork.JoinLobby(TypedLobby.Default);
    29.         Debug.Log("Connected");
    30.     }
    31.  
    32.     public void ChangeUsernameInput()
    33.     {
    34.         if (UsernameInput.text.Length >= 3)
    35.         {
    36.             StartButton.SetActive(true);
    37.         }
    38.         else
    39.         {
    40.             StartButton.SetActive(false);
    41.         }
    42.     }
    43.     public void SetUserName()
    44.     {
    45.         UsernameMenu.SetActive(false);
    46.         PhotonNetwork.playerName = UsernameInput.text;
    47.     }
    48.    
    49.     public void CreateGame()
    50.     {
    51.         PhotonNetwork.CreateRoom(CreateGameInput.text, new RoomOptions() { maxPlayers = 3 }, null);
    52.     }
    53. }
    54.  
    Inspector:
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,777
    The two fields you have left are both InputField type. Do the objects you're trying to drag into those slots have an Input Field component on them?

    It's possible that you've used the TextMeshPro variants of those components, in which case you will need to use the TMP_InputField on lines 12-14. (TMP's functions are compatible with regular UI elements so other code using these would not be affected by this change)
     
  3. RubenVanOostveen

    RubenVanOostveen

    Joined:
    Jul 31, 2020
    Posts:
    91
    i have used TMP Like i said and switched back due to the person in the video didn't use it.

    However when i try to put in Input field in it i get this error:

    I tried draging it out of the canvas seperating the text but nothing work.
    Inspector:
     
  4. RubenVanOostveen

    RubenVanOostveen

    Joined:
    Jul 31, 2020
    Posts:
    91
  5. Elango

    Elango

    Joined:
    Jan 27, 2016
    Posts:
    107
    The first error means that there is no "InputField" component on the object you are trying to drag into the inspector field. Your screenshots do not show any "InputField" except Username.

    The second error is due to the fact that you are trying to add an "InputField" component to an object that already has a "Button" component. They both inherit from the "Selectable" class which has a [DisallowMultipleComponent] attribute, so this is not allowed.
    https://docs.unity3d.com/ScriptReference/DisallowMultipleComponent.html

    If you are "following the tutorial" then you missed 2 "InputField" objects for CreateGameInput and JoinGameInput fields (rewatch video 2:50).
     
  6. RubenVanOostveen

    RubenVanOostveen

    Joined:
    Jul 31, 2020
    Posts:
    91
    Where you live wanna hug you....



    Jk thanks brother!
     
  7. mattiagualtieri

    mattiagualtieri

    Joined:
    Feb 27, 2022
    Posts:
    1
    Thank you so much!!
     
  8. striper28

    striper28

    Joined:
    Feb 19, 2016
    Posts:
    1
    In 2023: Thank you so much for noting the difference in variable name for Text Mesh Pro. This syntax now is "TMPro.TMP_InputField" as opposed to "InputField". I doubt i would have figured this out with your comments here. Thank you so much. It's helpful people like you that give me hope for the world.
     
    AxQuestion likes this.