x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Storing values after Destroying actor

I have a projectile that is spawned when the player fires. The projectile creates a actor(soundTarget) when it hits a wall, then destroys itself.

The next time the player fires, the new projectile should be able to find the reference to the actor(SoundTarget) that was previously created and replace it with its own, then destroy itself again.

So a reference variable to SoundTarget should always exist, and be updated/replaced every time the player fires. But since the projectile gets destroyed, it doesn't get maintained. I tried linking the projectile to a controller which I was hoping to use as just a repository for the reference variable, but when i call the controller at the beginning of the script it always fails. What am I doing wrong. Should I even be using a controller bp in that way?

The projectile is a pawn class, and I do have it referencing the controller.

Here is the script. https://blueprintue.com/blueprint/bhwvdj3k/

Product Version: UE 4.21
Tags:
more ▼

asked Apr 23 '19 at 07:49 PM in Blueprint Scripting

avatar image

Sentmassen
24 3 3

avatar image ClockworkOcean Apr 24 '19 at 12:22 PM

A little confused... why not just spawn the sound each time as well as the projectile? Why keep it in a variable?

avatar image Sentmassen Apr 24 '19 at 06:08 PM

I guess the complication comes from wanting to destroy the previous "SoundTarget" and replacing it with a new one.

The "SoundTarget" actor serves as a distraction that the enemy's can lock onto. The player can lob something like a glass bottle, and if its inside an enemy's sensing radius, he will go to it. If the player throws a new bottle, a new "SoundTarget" is created and the enemy should go to the new one, disregarding (destroying) the old one. I could have this grab all instances of the "SoundTarget" actor and destroy them all, but there are situations where I wouldn't want to do that. Like if I have two enemy who I need to distract separately. It won't work if in distracting one, I reset the other. So I need the ability to reference specific instances of the "SoundTarget" which I put into variables.

But this misses the main question. I cast a variable to the Projectile's controller, with the hopes of grabbing it later, after this Actor destroys itself. alt text But when I try to get that variable back from the controller when a new projectile gets a hit response, it fails to recognize the controller. Why is it failing? alt text

controller.png (72.1 kB)
controller2.png (72.1 kB)
avatar image HarryHighDef Apr 24 '19 at 02:40 PM

Maintain the reference to the sound target in the thing that spawns the projectile?

avatar image Sentmassen Apr 24 '19 at 06:15 PM

Is this any different than sending the reference to the Controller? I'll try it, and if it works, it works. But I would still like to know why the cast to the projectile's controller "Rock_Controller" fails every time.

The controller doesn't get destroyed when the actorBP get destroyed, does it?

avatar image ClockworkOcean Apr 24 '19 at 07:33 PM

I'm not sure why the cast fails, but I think you're overthinking the work of the projectile. You don't need to manage the sound.

You can put the sound with the projectile and let it die ( or be killed ) naturally ( as stated above ).

This way, if the enemy is near enough they will go in the correct direction, but it wont pull enemies from further away...

avatar image Nebula Games Inc Apr 24 '19 at 11:03 PM

The ONLY reason this would fail is if the projectile doesn't use the "controller" type specified. To be honest this is one of the weirdest setups I have seen. You have a "projectile" that is a "pawn"?? Are you controlling this projectile? If you are "firing" a projectile unless this is some Call Of Duty drone missile you are then directing towards a target a controller has no business being a part of this process at all. You "control" a player character....if you cast to your player character controller from within the player character I bet it succeeds. Your projectile "fails" this controller every time because it isn't using a controller...and if you set it to use one (since it is a pawn and theoretically could have one assigned) you have assigned the wrong one.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question