[SerializeField] private InputField Cannot drag button.

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:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MenuController : MonoBehaviour
{
    [SerializeField] private string VersioName = "0.1";
    [SerializeField] private GameObject UsernameMenu;
    [SerializeField] private GameObject ConnectPanel;

    [SerializeField] private InputField UsernameInput;
    [SerializeField] private InputField CreateGameInput;
    [SerializeField] private InputField JoinGameInput;

    [SerializeField] private GameObject StartButton;
    private void Awake()
    {
        PhotonNetwork.ConnectUsingSettings(VersioName);
    }

    private void Start()
    {
        UsernameMenu.SetActive(true);
    }
    private void OnConnectedToMaster()
    {
        PhotonNetwork.JoinLobby(TypedLobby.Default);
        Debug.Log("Connected");
    }

    public void ChangeUsernameInput()
    {
        if (UsernameInput.text.Length >= 3)
        {
            StartButton.SetActive(true);
        }
        else
        {
            StartButton.SetActive(false);
        }
    }
    public void SetUserName()
    {
        UsernameMenu.SetActive(false);
        PhotonNetwork.playerName = UsernameInput.text;
    }
   
    public void CreateGame()
    {
        PhotonNetwork.CreateRoom(CreateGameInput.text, new RoomOptions() { maxPlayers = 3 }, null);
    }
}

Inspector:

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)

5 Likes

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:

Buff

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.

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

Where you live wanna hug you…

Jk thanks brother!

Thank you so much!!

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.

1 Like