Blueprint variable not working

Im passing a reference from one blueprint to another for a picked up weapon but when I destroy the actor after I pick it up my reference while still stored does not work as expected.

You’re saying it yourself, it’s a reference, not a copy. So when you destroy it, you can’t do anything with it anymore. That’s normal behavior. Unless I misunderstand the question.

1 Like

When I pass other other variables from objects and then destroy that object I still have that reference object set. So Im not understanding why this is as intended. After I destroy this object I still have that local reference being set. Is there another way to achieve this then?

You have the reference, but the the object is marked as PendingKill and is not valid anymore. The object still exists in the invalid from until the garbage collector kicks in, but you can’t use it anymore.
What do you want to do with the object after it’s destroyed anyway?

Hey @DocThunda
If you make a copy of the object, you can store it elsewhere while still deleting PendingKill.

I hope this can help you out!

@ZenLeviathan If you could provide an example or point me to the documentation on how to do this that would be great.

Im using it to pass a picked up weapon to a player which has 2 local variables to hold that passed reference to be used later.

Bumping this to see if any one knows how to accomplish what I’m trying to do

I got you if you be a little more specific, what problem are you actually having? are you destroying it as part of your pickup system. is it destroyed later from gameplay? Are you making reference on pickup and getting rid of reference on destruction? Do you have any code up there that will set your “Current Equipped” variable to “none” when you aren’t holding anything?

Sorry for the late reply been busy with some other issues.
Basically what I’m doing is using a ray trace to check the item Im interacting with.
Im passing that item into a local variable by just using a set node and piping the raytrace hit into that. Im able to equip that item via attach to component.

I’ve worked out how to spawn other items using spawn actor but those are easier as the are not changing like a weapon could be if that makes sense.

I want to be able to pick up a weapon and swap between my health pack for instance then back to my weapon

I’ve attached screenshots to hopefully show what I’m doing.

Thank you,

Oh, if you “destroy” anything. you gotta get a new reference for it. like if when you put something away like your “pills” and you “destroy it” you have to get a set it as a reference again after you spawn it in your hand or wherever. so it would be like : You pick up painkiller, it “destroys” and you send a “custom event” to your character or wherever you are pulling your “inventory” from, that sets up a bool that says, “yeah I have a painkiller” then if you try to pull on out, it sees -“yeah I have a painkiller” spawn one in hand or weapon or whatever you destroyed. Then when you spawned it set the new one as the reference. Basically kill references to anything you “destroyed” because they are useless.
The reference isn’t for just “gun” or “painkiller” in general. its a reference to “THAT SPECIFIC ONE” I feel like explaining that will just set you off in the right direction in general… THE REFERENCE IS TO THAT PARTICUALAR OBJECT IF DESTROYED THE REFERENCE IS USELESS. See how you “destroyed” that weapon with your “clear slot” code. You gotta spawn the weapon every time, if you’re trying to have code that just “knows” what weapon to spawn every time, have your pickups set up “booleans” like “has smg” or “has shotgun” or maybe even think about using “class references” instead. but I like booleans, because you could even store stuff like what attachments those weapons currently have.

Thank you so much for helping out. This helped guide me to what I needed to make the system work as intended

1 Like