"Field " " is never assigned to, and will always have it's default value null"
Hi im 100% new to coding I was following this tutorial for a quiz https://www.youtube.com/watch?v=zLnnpUsxu0U and I'm done but it keeps giving me this warning in monodevelop "Field "__ " is never assigned to, and will always have it's default value null. the problem is
[SerializeField]
private Text factText;
to
[SerializeField]
private Animator animator;
heres the code (c#)
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.SceneManagement;
public class GameManager1 : MonoBehaviour {
public Questions[] questions;
private static List<Questions> unansweredQuestions;
private Questions currentQuestion;
[SerializeField]
private Text factText;
[SerializeField]
private Text trueAnswerText;
[SerializeField]
private Text falseAnswerText;
[SerializeField]
private Animator animator;
[SerializeField]
private float timeBetweenQuestions = 1f;
void start ()
{
if (unansweredQuestions == null || unansweredQuestions.Count == 0)
{
unansweredQuestions = questions.ToList<Questions>();
}
SetCurrentQuestion();
}
void SetCurrentQuestion ()
{
int randomQuestionIndex = Random.Range(0, unansweredQuestions.Count);
currentQuestion = unansweredQuestions[randomQuestionIndex];
factText.text = currentQuestion.fact;
if (currentQuestion.isTrue)
{
trueAnswerText.text = "CORRECT";
falseAnswerText.text = "WRONG";
} else
{
trueAnswerText.text = "WRONG";
falseAnswerText.text = "CORRECT";
}
}
IEnumerator TransitionToNextQuestion ()
{
unansweredQuestions.Remove(currentQuestion);
yield return new WaitForSeconds(timeBetweenQuestions);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
public void UserSelectTrue ()
{
animator.SetTrigger("True");
if (currentQuestion.isTrue)
{
Debug.Log("CORRECT!");
} else
{
Debug.Log("WRONG!");
}
StartCoroutine(TransitionToNextQuestion());
}
Answer by Axeavius · Feb 10, 2018 at 04:58 AM
I just ran into this in Visual Studio. This happens whenever you try to compile your code in MonoDevelop/Visual Studio. If you clean your solution (right-click on your project and choose "Clean Solution"), then the warning messages will go away.
Answer by HenryStrattonFW · Feb 15, 2017 at 10:12 PM
If your '__' is supposed to mean "insert variable name here" Then this warning is often completely ignore-able, as most values that are intended to be set in the inspector will of course as far as the compiler is concerned, never actually be getting set, and so the compiler throws what it thinks of as valid warnings.
However if your '' actually meant it was saying '' as the field name, then I have no idea whats occurring as your script appears to have no variable by that name.
Your answer
Follow this Question
Related Questions
Input Command Issues 0 Answers
Unity5/C# beginner here! Need some scripting help :) <3 1 Answer
I need help with boss design. I am new to coding so any help would be nice. 0 Answers
joystick android 3d , help. 0 Answers
Input Command Issues 0 Answers