Having multiple components of the same type on the same GameObject?

What are some of the best examples (of usefulness) of having multiple components of the same type on the same GameObject?

“Why would anyone add multiple components of the same type on the same GameObject?”
What’s the best answer to that question?

I’m looking for as many excellent examples as possible.

Thank you!

Often you can add status effects by simply adding new components to a GameObject.

Its not unusual to have multiple joints of the same type on a GameObject.

Plenty of use cases for multiple colliders on the same GameObject.

1 Like

Sound fx, visual effect triggers. Components that have multiple actions, etc.

1 Like

Not direct answer regarding multiple components, but you can have component with an array/list, which can be treated kind of like multiple same components.

1 Like

Just depends on what you want to do.
There’s no overall upside or downside to it.

1 Like

This is probably the better way to do things, if not just because it’s easier than dealing with the component stack directly.

1 Like

Its perfectly fine, but if you have to put more than like 2-3 of the same thing, perhaps consider condensing them into a single component that has a public enum that allows you to switch what “type” it is.

So if it was a damage status effect component, instead of having ParalyzeComponent, BleedingComponent, BurnedComponent etc

You would have DamageStatusEffectComponent which would contain logic for all 3, with the public enum allowing you to switch which logic to actually use.

Something like:

public class DamageStatusEffect : Monobehaviour
{
    public enum StatusType
   {
      Paralyze,
      Bleed,
      Burned
   }

// use this via inspector to switch the type
public StatusType statusType;

public void Execute()
{
     if(statusType == StatusType.Paralyze)
    {
      // do something
     }
     else  if(statusType == StatusType.Bleed)
    {
      // do something else
    }
  else  if(statusType == StatusType.Burned)
    {
      // do something else
    }

}

}

Note that is just an example and is written freehand so likely to produce errors.

1 Like