Cast to HUD on actor overlap event does nothing in game, no compiler errors?

Hello all!

So in my test FPS level, I have an pickup which is an Actor with an overlap sphere that should add 15 seconds to the level time remaining. Float variable called TimeAdd with a value of 15 is contained in the ‘pickup’ Actor, but my logic on how to add the time to the HUD is clearly faulty.

I’ve had no problems with pickups that add health or ammo, so I figured casting to the Game Mode HUD I created would suffice.

Level time remaining is a float variable stored in my Gamemode BP, the time remaining float is then formated to {minutes} and {seconds}, which then is set in the Gamemode HUD.

From there, on overlapping the ‘pickup’, I attempt to Cast to my GameMode BP, and call a custom ‘add time’ function, play a sound, and destroy the actor.

My time remaining function which counts down time in the HUD takes ‘time remaining’ float + ‘time add’ (15 seconds), then attempts to set time remaining.

The Add Time function attempts to use the format time remaining function I’ve set up previously which converts the float time remaining to {minutes} and {seconds}. (I’m not sure if this is necessary for my add time function?)

Then, referencing the HUD, and grabbing the time remaining text in the HUD, I attempt to ‘set’ it.

No compiler errors, but when walking over the overlap sphere, nothing happens in game!

Any input is appreciated :slight_smile:

Hey @biodigitalJazzz

From there, on overlapping the ‘pickup’, I attempt to Cast to my GameMode BP, and call a custom ‘add time’ function, play a sound, and destroy the actor.

In this case you can’t cast to your GameMode. The OtherActor is the one overlapping the sphere, so your character you are moving inside this sphere.

So either you

  • Use GetGameMode and then cast to it after the overlap event (can be combined with a branch => IF OtherActor == MyActor THEN …)

Or

  • Use your character blueprint called e.g. MyCharacter and use the OtherActor pin with your CastToMyCharacter instead of CastToFPSGameMode
2 Likes

@L1z4rD89

Thanks for the tip. I was banging my head against this for a while, and I think it was just a combination of unfamiliarity with Unreal, as well as not grasping what a Cast is.

I could tell that generally speaking, my other code for updating the game clock would work just fine, but I could not wrap my head around Casts. Read a few tutorials and when I came back here and saw your response, I was elated. Simply getting GameMode and casting off of that worked perfectly, thanks for taking the time to assist!

1 Like

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