Cast to Actor from Actor not working


I’m creating an environmental simulation where populations of wildlife change on a daily basis from predation, hunting by player and natural deaths. When the player saves, the calendar is moved forward 1 day and a calculation is done for wildlife population (running on assumption predation happened overnight). Player saves by interacting with a cube actor I placed in the world using a sphere trace and event dispatcher called Interact.

When the player hits Interact on the SaveGameCube I want the SaveGameCube to cast to the DayNightCycle to access the date to save as a variable to be stored with animal population data in a table (in picture). I’ve tried to do this in multiple ways including ShereTraceByChannel, creating an actor variable type in the blueprint, GetActorsOfClass, but the cast fails. The event dispatcher from the third person character is working fine though. The animal populations is saved in a sublevel which I’ll add later once I’ve got this figured out.

I’m still getting used to casting and I’m really struggling to find out any good information about casting from different actors and not the third person character, specifically object related. Any help would be greatly appreciated!!

If the DayNightCycle is an actor in the level, then you can create a variable of that type (which you already seem to have) in your SaveGameCube and set it to Instance Editable as shown below.

Once you do that, you will be able to see the variable exposed to the details panel when you select a SaveGameCube from the level editor. You can then select the DayNightCycle by clicking on the variable dropdown list.

Now that your SaveGameCubes have a reference to the DayNightCycle right from the get go, you won’t need to do any traces or casting. Just get the variable and set its GameDate.

Awesome thanks so much man, I have been struggling with this for so long! I can really get going on my game now :):slight_smile: