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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Variables not showing in the Inspector

Discussion in 'Scripting' started by fdzingova, Jan 11, 2021.

  1. fdzingova

    fdzingova

    Joined:
    Jan 11, 2021
    Posts:
    4
    Hi i'm new at Unity, trying to make a small 2D game by tutorial. So here's the code, the problem is that my variables are not showing in the Inspector so i can set up the elements. Any help ?

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




    public class GameController : MonoBehaviour
    {

    public Player player;
    public InputField textEntryField;
    public Text logText;
    public Text currentText;

    [TextArea]
    public string introText;


    // Start is called before the first frame update
    void Start()
    {
    logText.text = introText;
    DisplayLocation();
    textEntryField.ActivateInputField();

    }

    // Update is called once per frame
    void Update()
    {

    }

    public void DisplayLocation()
    {
    string description = player.currentLocation.description + "\n";
    desription += player.currentLocation.GetConnectionsText();
    currentText.text = description;
    }
    }
     
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Please use code tags.

    Which of your fields do not show up? I assume your script did compile successfully and you created an empty game object and attached that script?
     
  3. fdzingova

    fdzingova

    Joined:
    Jan 11, 2021
    Posts:
    4
    it shows none of the viaribles.It compiled perfectly. I attached it to a empty game object yes. Here's a pic.
     

    Attached Files:

  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,724
    Do you have any errors in your console window?
    Did you remember to save your changes to the file in your code editor?
     
  5. fdzingova

    fdzingova

    Joined:
    Jan 11, 2021
    Posts:
    4
    No, nothing unfortunately. That's why i'm confused what can be the problem.
    I had similar problem with some previous script. I just changed some uppercases of my variables in the code and then it magically worked. I tried the same thing with this script but somehow it shows nothing. :/
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,724
    If you click on your script in the project folder, Unity will show a preview of the script in the preview window (bottom right corner usually). Does that preview of the script match what you see in your code editor?
     
  7. fdzingova

    fdzingova

    Joined:
    Jan 11, 2021
    Posts:
    4
    yes, totally the same. :(
     
  8. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,724
    Kinda stumping me then... It should work.

    If I were you I would close Unity, delete the Library folder inside the project (don't worry, everything inside there is temporary and Unity will recreate it), and reopen the project.
     
  9. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    I've run across some very strange Unity Editor behaviour with some special keywords.

    Can you try removing

    Code (CSharp):
    1. [TextArea]
    and see what happens?
     
    PraetorBlue likes this.
  10. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Oh, and check if you have a GameController file somewhere in a folder called "Editor"
     
    PraetorBlue likes this.
  11. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    685
    All fields worked fine for me in a test script. [TextArea] is correct.
    Try renaming the script file name and class name to something other than GameController. There may be a conflict, as mentioned.