Prowl icon indicating copy to clipboard operation
Prowl copied to clipboard

[Standalone] `[RequireComponent(typeof(T))]` does literally nothing

Open PaperPrototype opened this issue 2 months ago • 6 comments

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?

PaperPrototype avatar Oct 20 '25 05:10 PaperPrototype

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).

PaperPrototype avatar Oct 20 '25 05:10 PaperPrototype

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, ...>()]

Shadowblitz16 avatar Nov 04 '25 21:11 Shadowblitz16

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.

michaelsakharov avatar Nov 05 '25 01:11 michaelsakharov

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.

Shadowblitz16 avatar Nov 05 '25 21:11 Shadowblitz16

You might be better off combining those components. Or creating a single MonoBehaviour that uses 2 scriptable objects.

PaperPrototype avatar Nov 05 '25 21:11 PaperPrototype

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.

PaperPrototype avatar Nov 05 '25 21:11 PaperPrototype