This might sound like a dumb question, but I am trying to set a variable of a class in one of my Actions that is derived from MonoBehavior. So it's data types are standard floats. When I try to set a pubilc float with a SharedFloat, I get errors about there being no implicit conversion between "SharedFloat" and "float".
I tried, based on the examples in the Documentation:
// tried grabbing it from the Behavior Tree itself...
// tried mapping it to the shared float in the editor.
// The only way I can seem to get it to work is with the built-in "ToString()" conversion in BehaviorDesigner. Then convert the string to float.
This works...but I feel like it's slopping programming. Is there no direct cast? I hate to do a double-conversion any time I need to cast to float or Int, etc.
Do you folks have some thoughts on this?
Is this bad practice?
Is there a direct cast I'm missing? I'm not from a CS background, so sorry if it's obvious.
Thanks in advance for any help!!
I tried, based on the examples in the Documentation:
// tried grabbing it from the Behavior Tree itself...
C#:
float f_exampleFloat = (float)behaviorTree.GetVariable("MySharedFloatVariable") ; //casting to float doesn't work
float f_exampleFloat = (float)behaviorTree.GetVariable("MySharedFloatVariable") as float; //casting to float doesn't work
// tried mapping it to the shared float in the editor.
C#:
public SharedFloat MySharedFloatVariable; // mapped in Editor to correct global variable.
...
float f_exampleFloat = System.Convert.ToSingle(exampleFloat );//doesn't work, get invalid cast. MonoDevelop lets it build, but fails in Editor play.
float f_exampleFloat = System.Convert.ToDouble(exampleFloat );//doesn't work, get invalid cast. MonoDevelop lets it build, but fails in Editor play.
// The only way I can seem to get it to work is with the built-in "ToString()" conversion in BehaviorDesigner. Then convert the string to float.
C#:
public SharedFloat MySharedFloatVariable; // mapped in Editor to correct global variable.
...
float f_exampleFloat = (float)System.Convert.ToDouble( MySharedFloatVariable.ToString() );
This works...but I feel like it's slopping programming. Is there no direct cast? I hate to do a double-conversion any time I need to cast to float or Int, etc.
Do you folks have some thoughts on this?
Is this bad practice?
Is there a direct cast I'm missing? I'm not from a CS background, so sorry if it's obvious.
Thanks in advance for any help!!