[Standalone] `[RequireComponent(typeof(T))]` does literally nothing
Describe the bug
I have a FreeLook component that has a RequireComponent(typeof(Camera)) attribute
[RequireComponent(typeof(Camera))]
public class FreeLook : MonoBehaviour {
// stuff that depends on camera
}
When I add the FreeLook component I was expecting it to throw an error or something if there is no camera component on the same gameobject
To Reproduce
literally try using RequireComponent
Expected behavior Throwing an error
Additional context
Maybe instead of throwing an error remove the RequireComponent attribute entirely?
Lol, if you hover over it it says this so maybe doing this as the default behaviour would make sense?
Specifies that a GameObject must have certain components in addition to the one where this attribute is applied.
When this attribute is used on a component, the Prowl Game Engine will automatically add the required components to the GameObject if they are not already present. This ensures that the component has all its dependencies met. This attribute can only be applied to classes (typically components deriving from MonoBehaviour).
Please make a Roslyn analyzer for this so it's an error to pass non monobehavior types.
Maybe instead the new generic attributes could be used and code generators could be made to generate variadic arguments.
[RequireComponent<T1, T2, ...>()]
Please make a Roslyn analyzer for this so it's an error to pass non monobehavior types.
Maybe instead the new generic attributes could be used and code generators could be made to generate variadic arguments.
[RequireComponent<T1, T2, ...>()]
Im not really sure a Roslyn analyzer makes sense, Passing in a non-monobehavior type doesnt break anything, it will just not work as expected. Though im probably just gonna remove this attribute, i've never really liked it much in unity, since it force adds the component for you. It makes more sense for the components that depend on another, to spit out an error if that component isnt found, Its more efficient too.
Please make a Roslyn analyzer for this so it's an error to pass non monobehavior types. Maybe instead the new generic attributes could be used and code generators could be made to generate variadic arguments. [RequireComponent<T1, T2, ...>()]
Im not really sure a Roslyn analyzer makes sense, Passing in a non-monobehavior type doesnt break anything, it will just not work as expected. Though im probably just gonna remove this attribute, i've never really liked it much in unity, since it force adds the component for you. It makes more sense for the components that depend on another, to spit out an error if that component isnt found, Its more efficient too.
You could also make components that require each other require users to pass a reference to eachother, instead of implicitly using get component.
You might be better off combining those components. Or creating a single MonoBehaviour that uses 2 scriptable objects.
This issue was specifically for the standalone version. Afaik the Main branch of prowl does have an editor and this attribute works there. Also, my guess is that once the editor comes around it will be re-implemented.