My variable is in 2 states at the same time as per debugger
I'm seriously confused by the way MSVS presents things to me regarding my boolean var state.
There's a button handler that triggers property change:
GetComponent<Button>().onClick.AddListener(() => purchasableItem.Active = true);
purchasableItem is a ScriptableObject;
public bool Active
{
get
{
active = PlayerPrefs.GetInt(PrefName, prePurchased ? 1 : 0) != 0;
return active && Purchased;
}
set
{
active = value && Purchased;
if (active)
{
foreach(var e in mutuallyExlusiveWith)
{
e.Active = false;
}
}
PlayerPrefs.SetInt(PrefName, active ? 1 : 0);
Raise(active);
}
}
And here's the tricky part for me. When I break at "set", it seems like active got equal "true" at line
active = value && Purchased;
It even gets into the "true" branch of the condition below, BUT! if I unfold this variable in MSVS, then debugger starts showing active as false. And behave like it is false. What the?
What debug values do you get when you ensure the variables can't change post-access (e.g. maybe Purchased is a get-set accessor which flips its bool state after get)?
bool thisValue = value;
bool thisPurchased = Purchased;
active = thisValue && thisPurchased; // Are they still both true?
Answer by Braza · Feb 03, 2020 at 06:52 PM
https://i.imgur.com/MsQJhwX.gif - the whole sequence. Once I inspect the internal structure of "this->base", active value is changed immediately right on the same line of code.
Your answer
![](https://koobas.hobune.stream/wayback/20220612222620im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity instance missing in "Attach Unity Debugger", Visual Studio 2013. How do I fix this? 6 Answers
[ASP.NET] [WEB API] Problem with HttpWebRequest.ContentType 0 Answers
Build a UWP app in c# with scripting backend IL2CPP 0 Answers
Attaching debugger to unity game running on HTC VIVE vr headset 0 Answers
Save a picture of a maze 1 Answer