How do you add a custom parameter and register to be used by EmotionFX Animation Graph?
I’m not 100% sure what you mean by custom parameter but I think there is two cases:
Adding a parameter to anim graph. In the anim graph layout, you first have to create or open an anim graph. Then looking for the Parameters tap. In the Parameter tap there is a Plus button. Click that will bring you to the Create Parameter window. There you could choose the value type, name, default value and such.
Adding a custom parameter type. To do that you have to write some C++ code. I would start with looking for any class that is inherited from ValueParameter class (Vector2Parameter is a good example). Look for how it is used in Gems/EMotionFX codebase. We tried to cover the common parameter type in our implementation but there could be something we missed. If you are trying to do this, may I ask what is the custom type you want to implement?
Let me know if this helps.
Thank you for using the lumberyard forum!
So I have been looking at BoolParameter class and the other class that are parameters, but cant get my custom parameter class to show in the EmotionFX editor.
My designers want an easy way transition condition to use our weapon types, since in the main player animation graph is just bouncing between different reference node(all referencing same animgraph just different motion sets).
Possible solutions that where tried:
- using a string parameter, easy to do since we have a function that you input the enum and returns you the string. Problem: It appears that none of the transition conditions work with a string parameter
- use a numerical parameter, easy to cast a enum into a numberically value. Problem: Designers forget which numerical value goes to which enum. So we have added the requirement: Add a dropdown to prevent the designers from entering invalid option into the condition.
- tried tags and bool parameters. Basically too many parameters need since we would need 8 different parameter and we are trying to simplify the logic need.
I’d recommend to either use tags or a numerical parameter. Tags, as you said, would result in more parameters. If they represent a given state that can be disabled/enabled of the character that would be a good solution, even if it results in many paramaters. You can create and move them into a parameter group to get these organized.
For using a numerical parameter we have the issue indeed that we have to deal with values rather than strings.
In order to get this to work with strings there are two things required:
1 Adding a custom parameter
We need to create a custom parameter that internally uses an integer but the UI is a custom one where you can map strings to the indices or something similar. You can follow what we did with the EMotionFX::TagParameter here, but rather than inheriting from a bool, we inherit from an IntParameter. Your new parameter needs to be reflected in ParameterFactory::ReflectParameterTypes() and added in ParameterFactory::GetValueParameterTypes() as well as AZ::TypeId GetParameterTypeIdForInterfaceType(uint32 interfaceType) and uint32 GetInterfaceTypeForParameterTypeId(const AZ::TypeId& parameterTypeId).
Next up we need a editor version of the parameter like the ParameterEditor which needs to get reflected in ParameterEditorFactory. For the editor parameter you would need a custom property handler for your integer (m_currentValue). The best is to use IntSpinnerParameterEditor as an example as the Tag one doesn’t deal with min and max values. In that custom widget you could do something that maps some strings to the indices or if its a const thing you can just hardcode it and use a combo box to set the edit context attribute for the m_currentValue.
2 Adding a custom transition condition
Now we got our custom parameter but in our state machine we still have to use the values for the conditions. That is why we also need a custom transition condition. We can use the AnimGraphTagCondition as an example again. That one also works with a custom property handler, so it will be a good example. Again, if the string to value map can be hardcoded, we can just use a combo box here to represent the value in the UI as strings. Your custom condtion needs to be reflected and added to the GetUITypes() in the AnimGraphObjectFactory.
That should do it. If the string to value map cannot be constant so that we can use a combo box, the custom property handler might be quite some additional work.
Hope this helped!