Can an UGameStateComponent be added to an AGameMode class?

I was reviewing the UGameStateComponente class and I read that it can belong to a Game Mode (red rectangles).

Does this mean that it can be added to an AGameMode class as component? It’s compatible?

Or is it some kind of ambiguous confusion?

Thank you so much!!


It would really be great if it was compatible.

It works!! I just tested it.

But since I don’t know if it is incompatible to avoid future problems, I have replaced it with a UActorComponent just in case. And it seems to work fine too.

But if anyone knows if UActorComponent cause problems with AGameMode please let me know.

Thank you so much!!

While there seems to be nothing in place that prevents you from adding a UGameStateComponent to an AGameMode you should probably avoid doing that. If you do and then call GetGameMode or GetGameStateChecked, the CastChecked will fail since the owner would not be an AGameState which is expected here.

You can directly use UActorComponent though or write your own UGameModeComponent similar to how UGameStateComponent works.

1 Like

Thank you very much for solving my doubt.
Definitely adding components to GameMode is extremely useful for keeping code clean and organized.

I’ll use UActorComponent in the meantime. I hope one day developers will make UGameModeComponent too.

Handling some GameMode events from the component would be very useful.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.