ActorComponent for Timefunction in GameState

Hello all and happy holidays;

I recently created/used a time and date system (thank you Nebula Games). This was done C++ ActorComponent (I think this was a mistake). I have it loading and producing properly within my GameState (aka it displays a timestamp properly). Here is a snippet from my GameStateBP

In my GameMenu HUD (UMG), I created a variable that is a reference to the actor component:

I then set out the links for the function.

I didn’t receive any compiling errors. Once I added the print string to let me know the cast was failing, I say it reported the cast was failing and of course due to the cast failing it was not putting the information into the HUD.

My problem: I do not understand why this is failing to cast. The C++ is working because it displays as expected when I play the level:

image

Any help would be appreciated. I feel like I should just do it as a different C++ file and not a component because its only in the GameState so that all players have access to it (so it replicates to all users).

Thank you all in advance o/

Quick Edit: I did make sure the gamestate is the same one set on the World Settings.

A step in fixing, but not fixed.

  1. I realized I didn’t expose the UClass to blueprints. So I added (after UCLASS) the following: UCLASS(Blueprintable, BlueprintType … )

  2. in UMG this opened up a propertie under the bindings:

I chose the World_Date and “Current_Year” for the text. I verified the information was producing as a string. However when I run it now (the casting error is gone because there is no casting or any function at all since I found the properties as shown), but now that area is blank.

Please note the “Date” showing is the box UNDER where I wanted the current year to be shown.

Not sure what I have missed :frowning:

What I have done to this point.

Within my GameMenu UI/HUD (UMG)

  1. I set the UMG text box as a variable so I could easily reference it within the graph.
  2. I created a reference to the component (more on this)
  3. I added an “? Is Valid” node as I suspected my reference is bad on the component.
  4. Added a not valid print text for debugging
  5. Casted to my C++ component class and pulled out the data I want from it.
  6. Added a SetText for it to populate the SST box (where I want the info to populate)

NOTE: For cause, I added the component to the scene’s sun

The data is available and showing in the scene debugger: (we will cover the This is not valid in a moment)

image

This returns us to the “This is not valid” As can be seen from my previous images, this is me checking the reference I created.

image

Here is my problem (updated problem as I try to resolve):

When I attempt to grabe the direct ActorComponent for reference (for the object section) I can “set it” or “get it” as expect. when I use a get, it still wants a target

image on hover it wants CG Game State BP Object Reference. In my game state bp (as reference and as captured in the first image of my original post) is where my function is to start the game calendar/time. No matter what option I choose, I am unable to get it to resolve as it just wants another target.

I am compoletely unsure what I need to reference. If I promote the target to a local variable, it still shows blank and fails the is valid. UGH Please someone help me fix my brain on this :wink:

I don’t entirely understand why the actor component is necessary. Why not just move all of your time logic to a C++ GameState class and cast to it via the “GetGameState” blueprint node?

1 Like

Thank you for responding, that is exactly what I did. I was going off an idea of creating actor components for an actor I was going to call time. Was a flawed concept. Going to mark yours as the answer, because that is again, what I ended up doing.

1 Like

For clarity, I thought I would show the final fix: