Referencing Integer in another BP? / casting

I’m trying to get the value of integer from another blueprint PuzzleBlock into PuzzleBlockGrid, I know this question has been asked and answered a thousand times but I’ve tried all kinds of different objects and none of them work. I just cannot understand the logic behind it, sometimes it’s game mode, sometime’s player pawn etc. etc. and even when I dont get error the casting still fails. why? Sorry for asking the same question as everyone else but I’ve seriously tried so many different objects that were recommended in the answers of other posts and none of them worked :frowning: Thanks in advance.

I just did the exact same thing today and I used BPI instead of casting since I need it for several characters. Even so, the engine tax shouldn’t be any higher so it’s a possible solution.

The benefit is that it is easily reusable for any value in any blueprint. If you need to set the value and keep it set you just need a new function with exact same setup for other variables. If it just needs to receive it once you can reuse the same function again and again.

Update to that, instead of “other actor” you can use get player character or whatever you want really.

I tried looking into it but basically everything you said in that thread went over my head. :frowning: Maybe I’m just too stupid >.< I know I was once able to do this when I followed a guide from youtube but that time I used “cast to player character” or smthing, but that BP doesnt even exist in the puzzle set up and doesnt work.

Oh, well you just have to make it cast to YOUR character blueprint. Aka, what you called your character blueprint. The videos have their own names for them.

I tried What do I cast in the cast function? - Blueprint - Epic Developer Community Forums just now too but even that doesnt work, it still prints the string ‘hello’ indicating that the casting failed.

What am I missing :frowning:

but the puzzle template doesnt have character blueprint, my variable that Im trying to reference is in the “PuzzleBlock” BP, (which I’ve casted into) but it won’t work anyway, no matter what I choose as the “object”

A character blueprint is a blueprint class, not necessarily a character blueprint, ie playable character, as such. I’m guessing your PuzzleBlock Blueprint is in fact a character blueprint. Without seeing what you’re doing it is fairly difficult though. I’d also guess “Get player character” is what you want as the object.

All I really want is for the casting not to fail, and to be able to read the value of “dollars” int variable, but here are some images of the two blueprints:

Also I tried using get player character, it didnt work out:

What does the warning say? Will always fail or something like that?

‘Puzzle Block’ does not inherit from ‘Character’ ( Cast To PuzzleBlock would always fail).
[0091.77] Compile of PuzzleBlockGrid successful, but with 1 Warning(s) [in 248 ms] (/Game/PuzzleBP/Blueprints/PuzzleBlockGrid.PuzzleBlockGrid)

Also here’s pic:

267551-puzzleblock.jpg

Get owner & get parent actor don’t give a warning but they still fail and print the hello string, same with get all actors of class

Well the player character will definitely not work there, that’s for sure.

What class have you selected when you use get all actors of class?

Not sure if this answers your question but this is what I did when I attempted that:

Sorry for taking so long to reply, also, thanks for attempting to help me for so long :3

Whoops, right after posting that picture I realized what you meant, so I tried a few different actor classes, which I hadn’t noticed could be changed before, and after selecting Puzzle Block, the cast to finally worked. :3

Thanks for all your help!

No problem, glad it worked. Feel like we should’ve figured this out sooner haha

Easy to miss that one.