Referencing float variable from another blueprint

I’m using get game time in seconds as my timer. Basically, I have 2 buttons “start” and “stop”. When the ‘start button’ is pressed, it will store the particular time into ‘start time’ float variable, same goes for the “stop” button. I’m trying to reference it to use for subtraction to get the difference. And that would be the total time of the whole process. Is there an easy way to do this without casting in which I’m still new to unreal and casting is super confusing to me. Any help is appreciated.



Just use direct communication:

BluePrint Interfaces. Casting is the devil.

This video explains how to use BluePrint Interfaces instead of performance killing Casting. Learn this technique and it will change your BluePrint scripting life. You will easily be able to retrieve data from other blueprints using BluePrint Interfaces which is also better on performance than casting. I never using casting anymore for anything.

There’s nothing wrong with casting, people just mistakenly think it’s used for communication.

1 Like

Edit: Sorry just realised i didn’t state my issue here. So when i referenced the ‘start time’ from another BP when ‘start button’ is clicked, the float i get is 0.0 for some reason. Am i doing something wrong here? i feel like it’s an easy fix but im just too dumb to realise.
image

Do you have more than one actor of this class in the level?

I do have a button if that’s what your’e asking and components to trigger event.


How would i reference this start time float variable to another blueprint? guess it’s not an actor?

Not too worry about performance for my little project atm, seems like interface could be useful and this is actually my first time hearing it.

Add a tag to it thats unique and try Get All Actors of Class with Tag node. Then get 0 index to reference.
image

Do u mean the actual value of “Start Time” is 3.0, but the value u get from blueprint is 0.0? Probably u got the wrong reference.

I don’t understand why u put “Floor” node, u can just connect “Get Game Time in Seconds” to “Set Start Time”.
If u want to remove the decimal, use “Truncate” instead.

That’s the problem, i wanted to store the value and use the variable in another blueprint. As you can see in the ss, it’s showing 0.0 and the stop time just subtracted 0 instead of 3. As for floor and truncate arent they the same?

IMO your problem is either you are referencing the wrong blueprint or you are getting the variable before its value changes.

Truncate just removes .##, so basically rounds towards 0. With positive numbers the result is the same, but with negative numbers floor rounds down while Truncate rounds up.

floor( 1.5 ) = 1
truncate( 1.5 ) = 1

floor( -1.5 ) = -2
truncate( -1.5 ) = -1

Choosing one or the other is up to what you want. If it’s for performance reasons, don’t think there’s much difference if any.