- Home /
What does Unity use internally to apply animation curve values to Component fields? Reflection?
I'm writing a system where Component field values need to be updated many times during runtime, potentially every frame, based on certain conditions.
My trouble is that the functionality is Component agnostic - that is, it would work for any component - and the field names and values are determined dynamically. This means I can't specifically code something along the lines of GetComponent().someField = newValue;
.
I can achieve what I need to via Reflection, but that's really not ideal from a performance point of view (and Reflection.Emit isn't viable for iOS I hear...).
I'm curious about how Unity applies values from the built in animation functionality. Is it Reflection? Or perhaps some kind of cached dynamic runtime functions?
Reflection performance might be okay if FieldInfo objects get cached such that a single SetValue call is all that's needed to update a value. Any other solution I can think of requires either metaprogram$$anonymous$$g (which I don't believe C# supports to the necessary extent) or putting responsibilities on client code (which sucks, and would only work for $$anonymous$$onoBehaviour subclasses).
Thanks for the input. Totally agree re putting responsibility on client code. Not at all ideal.
$$anonymous$$y prototypes thus far are leaning towards caching, and I'm learning about Delegates now, too.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Animation at the end of the level 1 Answer