Why can't I cast to GameInstance from actors?

I’m only two weeks into learning Unreal, and I know there are things I definitely don’t understand fully, so please be patient.

Every time a certain object (blueprint for spawning ammo) overlaps with character, I need to store which one of these in the map has been picked up in an array. At the moment, that’s stored in the game instance (as I really can’t see how to store persistent variables after literal days of googling).

The game mode bp is doing its job, spawning 5 random ammo actors, but casting to the gameinstance every time to add to the array, then checking that the next one to spawn isn’t already in the array. So I can cast from GameMode to GameInstance no problem.

However, try to get an ammo bp to cast to GameInstance on overlap, and I’m met with “‘ReturnValue’ is already a ‘Game Instance’, you don’t need Cast To GameInstance .” on the CastTo node, and “This blueprint (self) is not a BP_GameInstance_C, therefore ’ Target ’ must have a connection.”

I know this is due to me misunderstanding how casting works, even though sometimes I can get it to work great. Can anyone help?

Think the return value for Get Game Instance is of type GameInstance so there is no need to cast to that class. Perhaps in your case the cast should be to BP_GameInstance, not GameInstance.

2 Likes

How could I get that wrong?! Thank you, owe you a drink bud!

1 Like

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