I have a checkedListBox where the user can select whatever they want to update. I want them to be able to freely update 1 up to 5 characteristics of a machine. So when they only want to update 1 thing, they do not have to provide the other 4 characteristics. Also, when they want to update 5 characteristics, they
can do it in one go. For that purpose I have the following if statements:
if (clbCharacteristicsToUpdate.CheckedItems.Count != 0)
{
if (clbCharacteristicsToUpdate.GetSelected(0))
{
currentITime = Convert.ToDouble(tbCurrentITime.Text);
MessageBox.Show(currentITime.ToString());
dh.UpdateCurrentITime(machineNr, currentITime);
}
if (clbCharacteristicsToUpdate.GetSelected(1))
{
cycleTime = Convert.ToDouble(tbCycleTime.Text);
MessageBox.Show(cycleTime.ToString());
dh.UpdateCycleTime(machineNr, cycleTime);
}
if (clbCharacteristicsToUpdate.GetSelected(2))
{
nrOfLinesPerCm = Convert.ToInt32(tbNrOfLinesPerCm.Text);
MessageBox.Show(nrOfLinesPerCm.ToString());
dh.UpdateNrOfLinesPerCm(machineNr, nrOfLinesPerCm);
}
if (clbCharacteristicsToUpdate.GetSelected(3))
{
heightOfLamallae = Convert.ToDouble(tbHeightOfLamallae.Text);
MessageBox.Show(heightOfLamallae.ToString());
dh.UpdateHeightOfLamallae(machineNr, heightOfLamallae);
}
if (clbCharacteristicsToUpdate.GetSelected(4))
{
if (rbLTB.Checked)
{
machineType = 2;
MessageBox.Show(machineType.ToString());
}
else if (rbSTB.Checked)
{
machineType = 1;
MessageBox.Show(machineType.ToString());
}
if(!rbLTB.Checked && !rbSTB.Checked)
{
MessageBox.Show("Select a machine type to update!");
return;
}
dh.UpdateType(machineNr, machineType);
}
}
My problem is that, when I choose and update 1 thing it works perfectly. But when I choose multiple ones, it only executes the last if statement that returns true. I thought about using if-else but then only the first one that returns true will be executed. I also thought about having if statements for each possibility. But since I have 5 characteristics I can update, this would make 25 possibilities and I do not want to have 25 if statements. Thanks in advance!
GetSelected does not check whether the item has been checked, but that it is actually selected.
For example, in the below image "Item 2" will will return true for GetSelected. It is selected, not checked.
Instead you could do something like checking the clbCharacteristicsToUpdate.CheckedItems property to get the items that are actually checked.
The GetSelected method actually comes from the ListBox class, which CheckedListBox inherits from.
Try this:
This is a helper method I created on a button.
private void button1_Click(object sender, EventArgs e)
{
CheckList();
}
This method looks if items are checked and iterates over the collection of checked ones, calling the last metod.
private void CheckList()
{
if (clbCharacteristicsToUpdate.SelectedItems.Count != 0)
{
foreach (int indexChecked in clbCharacteristicsToUpdate.CheckedIndices)
{
CheckSelectedItem(indexChecked);
}
}
}
And finally, here the appropriate actions are taken based on indexes.
private void CheckSelectedItem(int index)
{
if (index == 0)
{
//Do stuff on Zero
MessageBox.Show("Zero");
}
if (index == 3)
{
//Do stuff on One
MessageBox.Show("Three");
}
}
I'm making a Unity C# script that is meant to be used by other people as a character dialog tool to write out conversations between multiple game characters.
I have a DialogueElement class and then I create a list of DialogueElement objects. Each object represents a line of dialogue.
[System.Serializable] //needed to make ScriptableObject out of this class
public class DialogueElement
{
public enum Characters {CharacterA, CharacterB};
public Characters Character; //Which characters is saying the line of dialog
public string DialogueText; //What the character is saying
}
public class Dialogue : ScriptableObject
{
public string[] CharactersList; //defined by the user in the Unity inspector
public List<DialogueElement> DialogueItems; //each element represents a line of dialogue
}
I want the user to be able to use the dialog tool by only interacting with the Unity inspector (so no editing code). The problem with this setup then is that the user of the dialogue tool cannot specify their own custom names (such as Felix or Wendy) for the characters in the Characters enum since they are hardcoded as "CharacterA" and "CharacterB" in the DialogueElement class.
For those not familiar with Unity, it is a game creation program. Unity lets users create physical files (known as scriptable objects) that acts as containers for class objects. The public variables of the scriptable object can be defined through a visual interface called the "inspector" as you can see below:
I want to use an enum to specify which characters is the one saying the line of dialog because using an enum creates a nice drop-down menu in the inspector where the user can easily select the character without having to manually type the name of the character for each line of dialogue.
How can I allow the user to define the elements of the Characters enum? In this case I was trying to use a string array variable where the player can type the name of all the possible characters and then use that array to define the enum.
I don't know if solving the problem this way is possible. I'm open to ANY ideas that will allow the user to specify a list of names that can then be used to create a drop down menu in the inspector where the user selects one of the names as seen in the image above.
The solution doesn't need to specifically declare a new enum from a string array. I just want to find a way to make this work. One solution I thought of is to write a separate script that would edit the text of the C# script that contains the Character enum. I think this would technically work since Unity automatically recompiles scripts every time it detects they were changed and updates the scriptable objects in the inspector, but I was hoping to find a cleaner way.
Link to repository for reference:
https://github.com/guitarjorge24/DialogueTool
You can't change the enum itself as it needs to be compiled (well it is not completely impossible but I wouldn't recommend to go ways like actively change a script and force a re-compile)
Without seeing the rest of the types you need it is a bit hard but what you want you would best do in a custom editor script using EditorGUILayout.Popup. As said I don't know your exact needs and the type Characters or how exactly you reference them so for now I will assume you reference your DialogueElement to a certain character via its index in the list Dialogue.CharactersList. This basically works like an enum then!
Since these editor scripts can get quite complex I try to comment every step:
using System;
using System.Collections.Generic;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditorInternal;
#endif
using UnityEngine;
[CreateAssetMenu]
public class Dialogue : ScriptableObject
{
public string[] CharactersList;
public List<DialogueElement> DialogueItems;
}
[Serializable] //needed to make ScriptableObject out of this class
public class DialogueElement
{
// You would only store an index to the according character
// Since I don't have your Characters type for now lets reference them via the Dialogue.CharactersList
public int CharacterID;
//public Characters Character;
// By using the attribute [TextArea] this creates a nice multi-line text are field
// You could further configure it with a min and max line size if you want: [TextArea(minLines, maxLines)]
[TextArea] public string DialogueText;
}
// This needs to be either wrapped by #if UNITY_EDITOR
// or placed in a folder called "Editor"
#if UNITY_EDITOR
[CustomEditor(typeof(Dialogue))]
public class DialogueEditor : Editor
{
// This will be the serialized clone property of Dialogue.CharacterList
private SerializedProperty CharactersList;
// This will be the serialized clone property of Dialogue.DialogueItems
private SerializedProperty DialogueItems;
// This is a little bonus from my side!
// These Lists are extremely more powerful then the default presentation of lists!
// you can/have to implement completely custom behavior of how to display and edit
// the list elements
private ReorderableList charactersList;
private ReorderableList dialogItemsList;
// Reference to the actual Dialogue instance this Inspector belongs to
private Dialogue dialogue;
// class field for storing available options
private GuiContent[] availableOptions;
// Called when the Inspector is opened / ScriptableObject is selected
private void OnEnable()
{
// Get the target as the type you are actually using
dialogue = (Dialogue) target;
// Link in serialized fields to their according SerializedProperties
CharactersList = serializedObject.FindProperty(nameof(Dialogue.CharactersList));
DialogueItems = serializedObject.FindProperty(nameof(Dialogue.DialogueItems));
// Setup and configure the charactersList we will use to display the content of the CharactersList
// in a nicer way
charactersList = new ReorderableList(serializedObject, CharactersList)
{
displayAdd = true,
displayRemove = true,
draggable = false, // for now disable reorder feature since we later go by index!
// As the header we simply want to see the usual display name of the CharactersList
drawHeaderCallback = rect => EditorGUI.LabelField(rect, CharactersList.displayName),
// How shall elements be displayed
drawElementCallback = (rect, index, focused, active) =>
{
// get the current element's SerializedProperty
var element = CharactersList.GetArrayElementAtIndex(index);
// Get all characters as string[]
var availableIDs = dialogue.CharactersList;
// store the original GUI.color
var color = GUI.color;
// Tint the field in red for invalid values
// either because it is empty or a duplicate
if(string.IsNullOrWhiteSpace(element.stringValue) || availableIDs.Count(item => string.Equals(item, element.stringValue)) > 1)
{
GUI.color = Color.red;
}
// Draw the property which automatically will select the correct drawer -> a single line text field
EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUI.GetPropertyHeight(element)), element);
// reset to the default color
GUI.color = color;
// If the value is invalid draw a HelpBox to explain why it is invalid
if (string.IsNullOrWhiteSpace(element.stringValue))
{
rect.y += EditorGUI.GetPropertyHeight(element);
EditorGUI.HelpBox(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), "ID may not be empty!", MessageType.Error );
}else if (availableIDs.Count(item => string.Equals(item, element.stringValue)) > 1)
{
rect.y += EditorGUI.GetPropertyHeight(element);
EditorGUI.HelpBox(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), "Duplicate! ID has to be unique!", MessageType.Error );
}
},
// Get the correct display height of elements in the list
// according to their values
// in this case e.g. dependent whether a HelpBox is displayed or not
elementHeightCallback = index =>
{
var element = CharactersList.GetArrayElementAtIndex(index);
var availableIDs = dialogue.CharactersList;
var height = EditorGUI.GetPropertyHeight(element);
if (string.IsNullOrWhiteSpace(element.stringValue) || availableIDs.Count(item => string.Equals(item, element.stringValue)) > 1)
{
height += EditorGUIUtility.singleLineHeight;
}
return height;
},
// Overwrite what shall be done when an element is added via the +
// Reset all values to the defaults for new added elements
// By default Unity would clone the values from the last or selected element otherwise
onAddCallback = list =>
{
// This adds the new element but copies all values of the select or last element in the list
list.serializedProperty.arraySize++;
var newElement = list.serializedProperty.GetArrayElementAtIndex(list.serializedProperty.arraySize - 1);
newElement.stringValue = "";
}
};
// Setup and configure the dialogItemsList we will use to display the content of the DialogueItems
// in a nicer way
dialogItemsList = new ReorderableList(serializedObject, DialogueItems)
{
displayAdd = true,
displayRemove = true,
draggable = true, // for the dialogue items we can allow re-ordering
// As the header we simply want to see the usual display name of the DialogueItems
drawHeaderCallback = rect => EditorGUI.LabelField(rect, DialogueItems.displayName),
// How shall elements be displayed
drawElementCallback = (rect, index, focused, active) =>
{
// get the current element's SerializedProperty
var element = DialogueItems.GetArrayElementAtIndex(index);
// Get the nested property fields of the DialogueElement class
var character = element.FindPropertyRelative(nameof(DialogueElement.CharacterID));
var text = element.FindPropertyRelative(nameof(DialogueElement.DialogueText));
var popUpHeight = EditorGUI.GetPropertyHeight(character);
// store the original GUI.color
var color = GUI.color;
// if the value is invalid tint the next field red
if(character.intValue < 0) GUI.color = Color.red;
// Draw the Popup so you can select from the existing character names
character.intValue = EditorGUI.Popup(new Rect(rect.x, rect.y, rect.width, popUpHeight), new GUIContent(character.displayName), character.intValue, availableOptions);
// reset the GUI.color
GUI.color = color;
rect.y += popUpHeight;
// Draw the text field
// since we use a PropertyField it will automatically recognize that this field is tagged [TextArea]
// and will choose the correct drawer accordingly
var textHeight = EditorGUI.GetPropertyHeight(text);
EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, textHeight), text);
},
// Get the correct display height of elements in the list
// according to their values
// in this case e.g. we add an additional line as a little spacing between elements
elementHeightCallback = index =>
{
var element = DialogueItems.GetArrayElementAtIndex(index);
var character = element.FindPropertyRelative(nameof(DialogueElement.CharacterID));
var text = element.FindPropertyRelative(nameof(DialogueElement.DialogueText));
return EditorGUI.GetPropertyHeight(character) + EditorGUI.GetPropertyHeight(text) + EditorGUIUtility.singleLineHeight;
},
// Overwrite what shall be done when an element is added via the +
// Reset all values to the defaults for new added elements
// By default Unity would clone the values from the last or selected element otherwise
onAddCallback = list =>
{
// This adds the new element but copies all values of the select or last element in the list
list.serializedProperty.arraySize++;
var newElement = list.serializedProperty.GetArrayElementAtIndex(list.serializedProperty.arraySize - 1);
var character = newElement.FindPropertyRelative(nameof(DialogueElement.CharacterID));
var text = newElement.FindPropertyRelative(nameof(DialogueElement.DialogueText));
character.intValue = -1;
text.stringValue = "";
}
};
// Get the existing character names ONCE as GuiContent[]
// Later only update this if the charcterList was changed
availableOptions = dialogue.CharactersList.Select(item => new GUIContent(item)).ToArray();
}
public override void OnInspectorGUI()
{
DrawScriptField();
// load real target values into SerializedProperties
serializedObject.Update();
EditorGUI.BeginChangeCheck();
charactersList.DoLayoutList();
if(EditorGUI.EndChangeCheck())
{
// Write back changed values into the real target
serializedObject.ApplyModifiedProperties();
// Update the existing character names as GuiContent[]
availableOptions = dialogue.CharactersList.Select(item => new GUIContent(item)).ToArray();
}
dialogItemsList.DoLayoutList();
// Write back changed values into the real target
serializedObject.ApplyModifiedProperties();
}
private void DrawScriptField()
{
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.ObjectField("Script", MonoScript.FromScriptableObject((Dialogue)target), typeof(Dialogue), false);
EditorGUI.EndDisabledGroup();
EditorGUILayout.Space();
}
}
#endif
And this is how it would look like now
Another option is to use an inspector enhancement asset like Odin Inspector or NaughtyAttributes.
So if you had this member:
public string[] CharactersList;
With Odin you would write:
[ValueDropdown("CharactersList")]
In NaughtyAttributes you would write:
[Dropdown("CharactersList")]
These solutions are similar to the suggestion by datsfain.
Although Odin is not free, it has tons of fancy extra functionality.
https://odininspector.com/attributes/value-dropdown-attribute
NaughtyAttributes is free but a bit older and more basic.
https://dbrizov.github.io/na-docs/attributes/drawer_attributes/dropdown.html
I'm going to write another answer... because double answers are better!
As derHugo said in his answer, it could be done using enums, but it would force a recompile. Well, sometimes maybe you just really want that enum (they are much faster than strings in some scenarios) and you're willing to accept the recompilation penalty.
So here's a little utility class I wrote for generating an enum and saving it to file.
Make a member variable with a list of strings that the designer can edit.
You'll probably want to put a button on your UI called "GenerateEnums" or something like that and perhaps a string for the save directory, which would call the save function and write the enum definition to file. There is code to force a recompile, so whenever the designer presses that button, they'll need to wait for a few seconds. Also, there is the chicken-and-egg problem - you can't reference the type until the definition has been generated at least once. Typically I get around that by just putting a file with the same filename in the intended location and giving it a dummy enum (like "public enum CharacterType { dummy }"). After the designer edits the string list, presses the generate button, and waits for a few seconds, they'll be able to see the updated selections in any fields that use that enum type (CharacterType in this example).
// this has a bunch of functions for generating enums in the editor
using System.Collections.Generic;
public static class EnumUtils
{
private static readonly HashSet<string> m_keywords = new HashSet<string> {
"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked",
"class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else",
"enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for",
"foreach", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock",
"long", "namespace", "new", "null", "object", "operator", "out", "override", "params",
"private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed",
"short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw",
"true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using",
"virtual", "void", "volatile", "while"
};
// This function will return a string containing an enum declaration with the specified parameters.
// name --> the name of the enum to create
// values -> the enum values
// primitive --> byte, int, uint, short, int64, etc (empty string means no type specifier)
// makeClassSize --> if this is true, an extra line will be added that makes a static class to hold the size.
// example:
// print(MakeEnumDeclaration("MyType", { Option1, Option2, Option3 }, "byte", true));
// output --> public enum MyType : byte { Option1, Option2, Option3 }
// public static class MyTypeSize { public const byte Size = 3; }
public static string MakeEnumDeclaration(string name, List<string> values, string primitive, bool makeSizeClass)
{
string prim = primitive.Length <= 0 ? "" : " : " + primitive;
string declaration = "public enum " + name + prim + " { ";
int countMinusOne = values.Count - 1;
for (int i = 0; i < values.Count; i++) {
declaration += MakeStringEnumCompatible(values[i]);
if (i < countMinusOne) { declaration += ", "; }
}
declaration += " }\n";
if (makeSizeClass) {
declaration += $"public static class {name}Size {{ public const {primitive} Size = {values.Count}; }}\n";
}
return declaration;
}
public static void WriteDeclarationToFile(string fileName, string declaration, bool reImport = false, string filePath = "Assets/Scripts/Generated/")
{
// ensure that the output directory exists
System.IO.Directory.CreateDirectory(filePath);
// write the file
System.IO.File.WriteAllText(filePath + fileName, "// This file was auto-generated\n\n" + declaration);
#if UNITY_EDITOR
if (reImport) { UnityEditor.AssetDatabase.ImportAsset(filePath); }
#endif
}
public static void WriteDeclarationsToFile(string fileName, List<string> declarations, bool reImport = false, string filePath = "Assets/Scripts/Generated/")
{
string text = "";
for (int i = 0; i < declarations.Count; i++) { text += declarations[i]; }
WriteDeclarationToFile(fileName, text, reImport, filePath);
}
// given a string, attempts to make the string compatible with an enum
// if there are any spaces, it will attempt to make the string camel-case
public static string MakeStringEnumCompatible(string text)
{
if (text.Length <= 0) { return "INVALID_ENUM_NAME"; }
string ret = "";
// first char must be a letter or an underscore, so ignore anything that is not
if (char.IsLetter(text[0]) || (text[0] == '_')) { ret += text[0]; }
// ignore anything that's not a digit or underscore
bool enableCapitalizeNextLetter = false;
for (int i = 1; i < text.Length; ++i) {
if (char.IsLetterOrDigit(text[i]) || (text[i] == '_')) {
if (enableCapitalizeNextLetter) {
ret += char.ToUpper(text[i]);
} else {
ret += text[i];
}
enableCapitalizeNextLetter = false;
} else if (char.IsWhiteSpace(text[i])) {
enableCapitalizeNextLetter = true;
}
}
if (ret.Length <= 0) { return "INVALID_ENUM_NAME"; }
// all the keywords are lowercase, so if we just change the first letter to uppercase,
// then there will be no conflict
if (m_keywords.Contains(ret)) { ret = char.ToUpper(ret[0]) + ret.Substring(1); }
return ret;
}
}
Caveats:
Keep in mind that this method is a bit brittle as with anytime you use an enum in the editor. Deleting or inserting an enum value in the middle of the values could cause any fields using that enum to use the wrong index because all the indexes will shift by one. There will be no compiler error and you could get weird activity at runtime.
Deleting or renaming an enum value might cause your code to stop compiling if you're using that enum value in your code (which is probably a good thing - with strings there is no compiler error and you'll get a silent confusing surprise at runtime).
For those who need enum like string dropdown, You can use code from my github repo.
download this folder and add it in your project.
https://github.com/datsfain/EditorCools/tree/main/Assets/EditorCools/DropdownStringAttribute
add following lines of code to any serializable class:
[Dropdown(nameof(MethodThatReturnsStringArray))]
public string options2;
I've recently taken on the task of custom properties in Photon. I have been able to figure out how to set the custom properties, but not get the custom properties. My hashtable is in my player controller script, while the place where I set (and where I want to get) properties is in a round loop script.
From RoundSystem:
private IEnumerator TeamBalance()
{
angelCount = Mathf.Floor(PhotonNetwork.PlayerList.Length * angelPercent);
currentAngels = angelCount;
currentPlayers = PhotonNetwork.PlayerList.Length;
foreach (var item in PhotonNetwork.PlayerList)
{
var itemPhotonView = (PhotonView)item.TagObject;
itemPhotonView.RPC("SetPlayerTeam", item, citiString);
}
for (int i = 0; i < angelCount;)
{
var item = PhotonNetwork.PlayerList[Random.Range(0, PhotonNetwork.PlayerList.Length)];
var itemPhotonView = (PhotonView)item.TagObject;
if (/* random player selected's, AKA, item's team == citiString */)
{
itemPhotonView.RPC("SetPlayerTeam", item, angelString);
i++;
}
}
yield return null;
//the reason this is in an IEnumerator with 'yield return null'
//is because I plan to add a waiting period once I figure this out
//it's for the game loop
}
From PlayerController:
[PunRPC]
public void SetPlayerTeam(string teamString)
{
//in the class: private ExitGames.Client.Photon.Hashtable playerProperties;
if (!playerProperties.ContainsKey("team"))
{
playerProperties.Add("team", teamString);
}
playerProperties["team"] = teamString;
PhotonNetwork.LocalPlayer.SetCustomProperties(playerProperties);
}
At the beginning of the round, a percentage (in this case 1/3) of players are chosen to be an "angel". The check here is needed because in cases of multiple angels, you don't want an already existing angel to count as a new change. (Also, it's probably important to known generally how to get custom properties if I'm going to be using them.) If I don't include the check in RoundSystem, the outcome is 2 citizens and 1 angel (in a test with 3 players). Also, if you see any spaghetti code that could be improved on, please don't hesitate to tell me. :)
Use Player.CustomProperties dictionary to access player's custom properties.
foreach (var item in PhotonNetwork.PlayerList)
{
if (item.CustomProperties.ContainsKey("team"))
{
Debug.Log(item.CustomProperties["team"]);
}
}
Also, the RoundSystem can implement IInRoomCallbacks interface and listen to OnPlayerPropertiesUpdate to catch the exact moment when the team gets updated. https://doc-api.photonengine.com/en/pun/v2/interface_photon_1_1_realtime_1_1_i_in_room_callbacks.html
A previously working Dictionary foreach loop is now suddenly broken (shown below). The dictionary stores data in the form of a struct, and is sorted/indexed based on a custom enum.
Previously it was working fine. Upon inspection/breakpoints, the data does exist/IS there, however Unity/C#/Something doesn't seem to be able to see the data suddenly.
There is no modification to that data in the foreach loop, the purpose is to simply determine if a List parameter in each struct is empty or not and set a boolean.
I'm at a total loss as to why this is happening, or what could cause it, so any suggestions is appreciated.
Original Class
TargetController.UpdateSensesListData();
foreach(KeyValuePair<Controller.TypeEnum, Controller.DataStruct> list in TargetController.SensesList)
{
if(list.Value.objects.Count > 0)
{
booleanVar = true;
break;
}
}
Controller Class
public class DataStruct
{
public int priority;
public Senses thisSense;
public List<GameObject> objects = new List<GameObject>();
}
public void Start()
{
//SensesPriorityList is set in the Unity Inspector. Its simply a list
// of the TypeEnums that are used as keys for the dictionary.
if(SensesPriorityList.count > 0)
{
for(int i = 0; i < SensesPriorityList.Count; i++)
{
DataStruct data = new DataStruct
{
priority = i,
sense = Getsense(SensesPriorityList[i]),
objects = new List<GameObject>()
};
SensesList.Add(SensesPriorityList[i], data);
}
}
}
public void UpdateSensesListData()
{
foreach(KeyValuePair<TypeEnum, DataStruct> sense in SensesList)
{
if(sense.Value.sense != null)
sense.Value.Objects = sense.Value.sense.UpdateSense();
if(sense.Value.objects.Count > 0)
break;
}
}
In the above example, "DictionaryVariable" DOES have data (is not null), and the second item in the dictionary has data (the count > 0) so it should for all intents and purposes be setting the bool to true. but its not. When I looked, list reads as "Null" (but upon closer inspection, the dictionary is not null, but rather the OtherClass.Struct data is null - when it is not)