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…
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.
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.
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.
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.
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.
…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 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!