mercredi 26 avril 2023

Only one Rigidbody can be added to a GameObject, yet Rigidbodies lack [DisallowMultipleComponentAttribute]. Why?

Obviously GameObjects should not have more than one Rigidbody. Yet, after digging through the source code, I don't see any attribute that would cause the behaviour.

namespace UnityEngine
{
...
    [RequireComponent(typeof(Transform))]
    [NativeHeader("Modules/Physics/Rigidbody.h")]
    public partial class Rigidbody : UnityEngine.Component
    {
    ...

How does UnityEngine know to not allow more than one Rigidbody on a GameObject? Is it in Rigidbody.h, or perhaps in some other editor script? I would like to determine if a component can be added to a GameObject using reflection, which is why I'm looking for a [DisallowMultipleComponent] attribute and am discombobulated by its absence.





Aucun commentaire:

Enregistrer un commentaire