I’m using custom attributes in my game to allow me to define dependencies between aggregated components.
[ComponentDependency(typeof(SomeDependentComponent))]
class SomeComponent : Component {}
However, this means I have to use default values for every component I want to add this way. I would like to be able to do:
[ComponentDependency(typeof(SomeDependentComponent), ctrParam1, ctrParam2...)]
And feed these directly into Activator.CreateInstance(Type, object[]), but I get errors. I think it’s to do with attributes being compile time. I don’t know much about them.
Is this possible?
EDIT: If I were to use parameters, it may look like:
[ComponentDependency(typeof(PositionalComponent), new Vector2(300, 300))]
You can’t.
Attributes are compiled to metadata in the assembly.
Attribute parameters can only be primitives or
Typeobjects.