can not convert object to bool?

I have a question around the documentation for OnPostprocessGameObjectWithUserProperties (support link). My problem is specifically boolean.

I see that I can read all of these things like int, string, ect as user attributes on the objects. And I have been able to cycle through them and read them off. They are recognized as what they are. It even recognizes the bool, just does not recognize Enum. But anyways now take a look at what I want to do here…

	void OnPostprocessGameObjectWithUserProperties (GameObject go, string[] names, object[] values) {
Debug.LogWarning("OnPostprocessGameObjectWithUserProperties for " + go.name);
		for (int i = 0; i < names.Length; i++) {
			Debug.Log("Name: " + names[i] + " --- Value: " + values[i] + " --- Type: " + values[i].GetType());
			if(names[i].ToLower() == "generatefile") {
				if(values[i].GetType() == bool){
					if(values[i]){
						Debug.Log("Yeay!");
					}
				}
			}
		}
	}

With that I get some parsing error?? if I take out the “if(values*.GetType() == bool)” statement then it works. So what am I doing wrong?*
I have the same problem with int, string, and everything else. I think the problem is based on the fact that the value (and type) come in as an object and I dont see how to convert that into a variable of that type. So if I had a bool attribuite and its value was true (this comes in as an object) then I would want to convert it to a local variable and set it up as a bool that equals true.
How do I do this?

I think you need to wrap the “bool” with typeof()

if(values*.GetType() == typeof(bool)){*
But perhaps better would be:
if (values is bool){

hey that worked!

Now I am only left with the problem of converting the object to an actual bool …

if(values*)*
gives me the following error … again it comes in as a object.
Assets/Backend Assets/AssetPostProcess/Editor/PostProcessForMaya.cs(80,41): error CS0266: Cannot implicitly convert type object' to bool’. An explicit conversion exists (are you missing a cast?)
What is interesting is that when i print values it showes the real value and when i print values*.GetType() it showes to be a System.Boolean*

Because it’s an “object”, you need to explicitly cast it to a boolean. Reason being, as far as the code knows at compile time, it is an object and could be anything, including types non-convertable to booleans. It could be a string, a GameObject, an XmlSerializer, etc. So you need to tell the code, “It’s OK, trust me, it’s a boolean!”

if ((bool)values*)*
But if you lied to the code, and the object isn’t actually a boolean (say it’s an integer), then an exception (I think InvalidCastException) will be thrown. So it’s important in cases like these to make sure it’s a boolean before casting it (which you have)
if (values is bool)
{
_ if ((bool)values*)
{
}
}*_

so to cast it i put what i want to cast it as in parenthesis in front of it like this …

if((int)values == 50) //if it were an int
You know that college degree I have in Art is really paying off :roll_eyes:

You mean like this?
if (values is bool (bool)values == true)
{
}
This will still go through two operations, but if the first one is false (values is NOT a bool) it doesn’t bother trying to cast it for the second half.