I'm getting a UnassignedReferenceException: The variable _Preset of Foo has not been assigned.
even though I'm using the null-conditional operator ?.
.
My code:
// […]
myTarget.Preset?.ApplyTo(myTarget);
I'm also noticing that it mentions _Preset
instead of Preset
(which I find odd).
Code in Foo.cs
:
[CreateAssetMenu()]
public class Foo : ScriptableObject
{
[SerializeField] private Preset _Preset = null;
public Preset Preset
{
get { return _Preset; }
protected set { _Preset = value; }
}
}
What am I doing wrong? Isn't it what the operator is for?
Google searches didn't help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…