UActorComponent dependency

Hello,

I am making some UActorComponent to represent rules, that will be attached to my custom Game Mode. I would like to be sure that my component is attached to my custom game mode or an inheriting class, to be sure that another developer don’t make mistakes by using it.

It’s not a blocking question for me, but I am still interested in the answer : Is there a way to apply some dependency/constraints on an UActorComponent to be attached only with some kind of actor ?
Or, more generally, can an UActorComponent process some check when it is attached to an actor and refuse/delete itself if it cannot ?

Thanks for reading.

Well, you can always cast your owner and check if it’s valid inside your Activate function:

APawn* pawn = Cast<APawn>(GetOwner());
if(pawn)
{
//owner is a pawn descendant
}

And if it’s not valid, then you can disable the object’s functionality with a bool or by deactivating it.
I don’t know if there is a better way (some macro magic or anything) for this

Yeah, pretty certain he’s after “Add Component - Time” results. I think it’d be very possible to constrain this in the editor, though at code compile time, it may be pretty difficult.

I didn’t know about the Activate function. Indeed, it’s seems a good place to process this check and maybe call DestroyComponent.
As it seems to be the best answer for now, I will make it as the thread answer.

Thank you for your time and explanation !