when we write in element in bindingpath field it can get and change variable by variable name. is it implemented through reflection?
When using bindingPath
you are interacting with the data through the SerializedObject
and SerializedProperty
abstractions. These are internally implemented on the native side of the engine, so i believe their source-code is not publicly available.
AFAIK, in the end, they have some custom serialization-backend that would generate code to directly read&write fields for the types that are serializable. I dont really know if this backend relies on Reflection code, but it is probably very likely.
On the other side there is another binding system (the Runtime Binding System) that uses the Unity.Properties API . This API leverages Roslyn SourceGenerators to create PropertyBags that offer direct access to fields. This is internally implemented through Reflection, but if you read the docs you can see that under certain conditions (your type is partial
and has the [GeneratePropertyBag]
attribute) they wont need Reflection and can directly access your fields.
PD: haha @martinpa_unity beated u yes
Hi @Bkhalay,
For the bindingPath
and editor bindings in general, this will end up using the SerializedObject
/SerializedProperty
system under the hood, which includes the use of reflection.
For dataSourcePath
and runtime bindings in general, this will end up using a generate PropertyBag
, which will be used to get/set fields/properties. That property bag object can either be generated using reflection or it can be code-generated using our own source generator. When the property bag is code-generated, we can avoid reflection usage as long as we have access to the fields/properties (i.e. they are public, or the type is marked as partial
, etc.)
Hope this helps!
(@Canijo beat me to it :P)
thank you, I understand