How to get a variable from a child actor to my Player blueprint?

Im trying to get a variable from my child actor flashlight to my Player
I have a variable that checks if the flashlight is equipped.


and I have this blueprint in my player character . im trying to cast the flashlight but somehow nothing is happening. please help

How did you set the variable “Actor” ?, if it not set it will return null and cast fail.

1 Like

I just made a variable with actor object reference in it. Should i set it? where to set it? begin play?

I just made a variable with actor object reference in it

Creating a variable does not instantiate the actor. Where is the my child actor flashlight instance? How does the player know which actor instance we’re talking about?

I have this blueprint for interactions


This is the blueprint for my interaction item parent. and I just override the function Destroy item In the flash light blueprint.

Not sure what you referring to. You asked how to access data inside an instance of the flashlight blueprint but here you’re showing how you destroy it.


im trying to cast the flashlight but somehow nothing is happening. please help

How do you set the value of this variable:

How does the player know which BP instance this is? Imagine there are 10 flashlights. How are you going to assign one of those flashlights to be referenced by this very variable?

  • how does the player know they have a flashlight?
  • do you spawn it?
  • do you pick it up from the ground?
  • does the character always have it?

Is this the flashlight?

Note we have no clue how your game works and how you organised it.

Sorry for being confusing. but In my player I have a line trace That checks if hit actor has interface like this:

and on my Item parent blueprint I have an inspect or pickup an item:


The inspect part is partly finished. And I only have the destroy item on the pickup line.

The flashlight I want to turn on is just a spotlight connected to the player camera and its visibility turned off, My plan is for the player to get the variable “Flashlight picked up” after interacting with the flashlight I placed on the level.

Im not planning to place more than 1 flashlight. so it didnt occur to me to choose what flashlight is being picked up. all the items in my game are just a child of the Parent blueprint with the inspect and destroy item code.

On the flashlight Item child blueprint. I just override the destroy item custom event on the parent blueprint. and Added a boolean variable that checks true after getting destroyed.

my problem as I understood from you comment is that the way im casting is wrong and that I didnt set the actor reference variable right.

.
only thing Im really confused is how to set the variable Actor object reference to get the boolean “IsFlashlight picked up”.

Sounds good. So we’re not really picking anything up per se. There can be no actor to cast because the flashlight actor gets destroyed, right?


only thing Im really confused is how to set the variable Actor object reference to get the boolean “IsFlashlight picked up”.

There seems to be no need. What if the player had the variable IsFlashlight picked up → set it True when you pick it up.

  • player line traces against world objects → interface message to interact (you got this already)
  • the interface returns some data regarding the object (or you can even have the flashlight set the player’s var before it gets destroyed - not ideal, though)
  • the player can use the data interface returned to manipulate its own variables