0
0
Unityframework~5 mins

Public vs SerializeField in Unity - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What does the public keyword do in Unity scripts?
It makes a variable accessible from other scripts and also visible and editable in the Unity Inspector.
Click to reveal answer
beginner
What is the purpose of the [SerializeField] attribute in Unity?
It makes a private variable visible and editable in the Unity Inspector without making it accessible from other scripts.
Click to reveal answer
intermediate
Why might you use [SerializeField] instead of public for a variable?
To keep the variable private (hidden from other scripts) but still editable in the Inspector, helping to protect your code from unwanted changes.
Click to reveal answer
beginner
Can a private variable without [SerializeField] be edited in the Unity Inspector?
No, private variables without [SerializeField] are hidden from the Inspector and cannot be edited there.
Click to reveal answer
beginner
What happens if you make a variable public but do not use [SerializeField]?
The variable is visible and editable in the Inspector and accessible from other scripts.
Click to reveal answer
Which keyword or attribute allows a private variable to be shown in the Unity Inspector?
A[SerializeField]
Bpublic
Cprivate
Dreadonly
What does making a variable public in Unity do?
AOnly makes it visible in the Inspector but not accessible from other scripts
BKeeps it private and hidden in the Inspector
CMakes it accessible from other scripts and visible in the Inspector
DPrevents it from being serialized
Why use [SerializeField] on a private variable?
ATo make it readonly
BTo make it public
CTo hide it from the Inspector
DTo edit it in the Inspector but keep it private to other scripts
If a variable is private and has no [SerializeField], can you edit it in the Inspector?
ANo
BYes
COnly if it is static
DOnly if it is const
Which is a good reason to keep a variable private but serialized?
ATo make it accessible everywhere
BTo protect it from unwanted changes by other scripts but allow editing in Inspector
CTo prevent it from being saved
DTo make it readonly
Explain the difference between using public and [SerializeField] for variables in Unity.
Think about accessibility and Inspector visibility separately.
You got /4 concepts.
    Why might a Unity developer prefer [SerializeField] over making variables public?
    Consider code safety and ease of editing.
    You got /3 concepts.