Download

Setting parent variable from instance

Newbie here is reaching out…

I’m making a FPS, featuring a launcher and a number of missiles. I want to prevent the player from launching another missile, before the first one has detonated or timed out.
For this, a variable in FPScharacter called “nuclearMissileLaunched” is set to TRUE and should be set to FALSE, when told so by the missile.

The issue is, that the variable is unavailable from the created instance. Is there a way to make it visible from within the missile?

I don’t want to use a global variable, as I want to learn good practice and that the map potentially involves two players.

Any help will be greatly appreciated.

FPScharacter, containing the launcher

The missile, created in FPScharacter

It is possible to reach back into the spawning actor to do this kind of thing, but a much easier way, is to manipulate the variable somewhere easily reachable from everywhere, like the game instance.

It sounds to me like you only ever need one missile per launcher.

What you could do is spawn the missile together with the launcher and then change the visibility/collision when the weapon is fired.
Then once the missile has detonated you can hide it again.

This way the launcher always has a reference to its missile and you simply need to check whether the missile is invisible or not to decide whether the weapon can be fired again.
Hope this helps!

Thank you for your suggestions. I’ll get back soon with visuals on the chosen solution, in case other people have similar problems.

Your character is not the parent class of your missile… it just spawned it.
You can do either:
A) on your firing event add a delay and set it back to false at the end
B) make the weapon its own actor and have a firing event dealing with it
C) On your missile create an Event Destroyed and get player character > Cast to That Character You Have > Set the bool to false

A lot of good advice in this thread, but I think best way to do this is to have an Event dispatcher in your missile that is called when Missile is destroyed. You can probably try to use the “On Destroyed” dispatcher.

So when your actors spawn the missile, bind to that dispatcher right away, and set the variable when the dispatcher calls.

Or even easier, instead of MissileLaunched variable, just check if the missile is still valid. Set it to a variable when you create it, and then whenever you need to check, see if the variable is still valid.

Hopefully that helps!