I am trying to use a variable from one actor in another actor however I have failed at understanding how to reference it though the cast to nodes. Is their a simple way of using a variable from one blueprint in another blueprint?
Good morning Tirrans,
To cast to an object, you need a reference of that object. In this case you are casting a player character (which is not a tree) into the cast to tree node, and as such it is failing.
You can get this reference from an on actoroverlap, on-hit, or various other means depending upon how you have your blueprint setup for chopping down trees.
I would need to see more of the blueprint on the right image (specifically how you are initializing the tree chopdown/gather wood part of it) if you want targeted help.
you should have just continued on your other thread since its pretty much the same topic.
on your begin overlap event script, right click the as tree pin on the cast and select promote to variable. this variable that is created will be a reference to the tree your overlapping. so from there all you will need to do is plug that variable (a get of the variable) into the object pin. actually once you have the variable setup you shouldnt actually need the cast where your getting the variables.
below is a picture of how you could modify your script to get it to work.
honestly i dont think this is the most optimal way to implement this functionality, personally i would have all of this scripting in the tree bp, but thats just my opinion.
Thank you for the detailed answer, you really helped me out
You can use a “Game Instance” instead, which is a very useful way of passing variables between multiple blueprints, and it even saves the value when the level changes. Just make a new blueprint class and search “Game Instance”. Then whenever you want to access it, just cast to the game instance with the “get game instance” as the object.