In the MyRangeDrawer class example, the “(float)instance” cast is not working.
Unity throws the following error: InvalidCastException: Specified cast is not valid.
I tested this with NodeCanvas v3.1.6, Unity 2020.1.17f1.
The error happens when I apply my custom attribute to a BBParameter<float> variable.
The documentation implies that cast should also work with BBParameter.
You are right. The code shown in the documentation is outdated and I have just updated that section. In practice, we need to check whether or not the type of the field we are currently “looking at” is of the required type we want and only if so proceed with the editor GUI code (and also the casting). Otherwise, we call MoveNextDrawer() by the end of the OnGUI method.
Please take a look at the updated documentation. You can also take a look at the various implemented attribute drawers that can be found in AttributeDrawers.cs file for a few more examples.