NPC will not destroy properly.

I have been dealing with this problem for over a week now and am coming up very short of ideas for how to cope with it. I’ve tried every debug I can think of and the nodes are simply behaving illogically. Here’s the general overview:

I have several NPCs that trigger conversations. In some cases, the outcome of those discussions will destroy the current NPC and replace it with a different version of the NPC, sometimes they spawn new NPCs in different places, sometimes they trigger missions. Most of this works perfectly, but for some reason I cannot figure out, I’m having a terrible issue with the most recent one. I have an NPC named NPC_JerryOldman_2AC. There is also a 2BC, a 2CC, and a 2D. Depending on how your conversation plays out, the one you’re talking with should spawn a different version and destroy the old one. I’ve tried this several different way. First I tried it with the auto destroy (which I have used before).


In this specific example, you got the bad outcome of the conversation, the End Chat would run, which give player control back and eliminates the conversation widgets. Then the auto destroy is turned on, the new version of the NPC is spawned, and another NPC in the area, if present, is turned into conversation mode by setting the Non-Discussion variable, where they then run their own Event. So, far, so good…accept…
image
The original NPC is not deleting.

I even tried changing the code up and going with a different approach by having the actor simply run a destroy function at the end. However, that yielded an unexpected result.


It interferes with the End Chat event (something that is never happened before) and doesn’t allow the widget to go away or control to return to the player.

I must admit, I’m at a total loss.

Is there a reason why you cannot simply call Destroy when needed? Also, you’re not referencing the newly spawned actor and then need to rely on Get Actor of Class which gets the first actor it finds, not necessarily the one you need. Could this be an issue? Also, no need to cast here.

Not sure what you mean by “referencing the newly spawned actor.” The get actor of class works in this situation because there is only one in the scene. When I call destroy “as needed” as you say, I get the second scenario I showed, where the End Chat event does not properly execute.


I’ve tried writing it this way, and I get that issue.

image

This. The return value is the reference. You assign this value to a variable so you can interact with this actor later, without needing to look anything up.

But there is no need. He simply needs to spawn and nothing else.

But you’re complaining about not being able to destroy it… so there is something else. What am I missing?


Where is the Destroy you call on the actor that refuses to go away?

I am not attempting to destroy the spawned NPC, I’m attempting to destroy the one who spawned it. The owner of the blueprint you’re seeing.

I remember, we talked about it twice already. My question stands: where / when do you call Destroy for this actor?

As shown in the blueprint I presented, at the end of it’s function. When the string of nodes ends, it should be destroyed. That’s why I set the auto destroy when finished, when the execution finishes, it should be destroyed, which works in other instances that I’ve used it in. It doesn’t work here. So I placed the destroy actor node with a reference to self at the end, and it interferes with the previous End Chat event. Again, I don’t know why it does this.

As shown in the blueprint I presented, at the end of it’s function. When the string of nodes ends, it should be destroyed.

No, it’s not shown. That’s not how it works, that’s not how auto-destroy works. It waits for other stuff to finish. This is how you call Destroy:

This actor gets destroyed, Jerry lives on.


Also, note:

If this manages to Destroy this actor, the rest of the script may not have a chance to execute… Actors asked to be destroyed are put on a Pending Kill stack and their script cannot be reliably executed.

Is that not what I’m doing here, that causes my End Chat to glitch?
image
Also here…


…the rest of the script does execute, just not the destroy, everything else works. When I debug and utilize print strings, everything executes without issue except for the destroy.

I could not see it in the original pic. If this final Destroy does not execute:

  • auto-destroy already destroyed it
  • the Get Actor of Class returns invalid (print Branch → Failed)
  • the cast failed (this is unlikely judging by the blue note)

Add this to the shown actor:

image

Does it trigger?

Okay.
image
It certain does.
image
Yet here he remains.

You may have more than one. Try:

What do you get? Providing you only wanted 1 at a time, you should be seeing either 0 or 1.


Alternatively. check in the Outliner - it shows all spawned BPs.

image
image
That’s fascinating! Now, I can ask the real question, why are 2 being spawned?

1 Like

Heh, that’s be something for you to figure out. Do tell how it goes. You can use breakpoints:

to step through the code - select any node and hit F9. Run the game.

I found the answer! Essentially, I had attempted two different versions of the spawn. One in which a conversation with another NPC (Dave Johnson) would trigger a search for which version of Jerry Oldman existed and replace him with the appropriate version. However, I also had an earlier version of the spawn within the various versions of Jerry Oldman (which I honestly forgot I even created) which caused them to spawn the appropriate replacement in the event they were destroyed. Thus, I had two spawns happening in unison. Considering the Dave Johnson NPC is doing the major legwork of the sequence anyway, I opted to eliminate the Event Destroyed version and now we are off and running. Thanks for putting up with me over the last few days and helping me work this out!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.