Destroy actor issue

Hi,

I am having an issue with a destroy actor and I can’t figure out what could have gone wrong. Basically, I created a timer and when this ends it destroys the actor, however when this occurs the actor disappears but the camera stays static in the same place and doesn’t appear, it is like something has been broken with the respawn.

It is very strange as this was working perfectly before I introduced the timer and even though I disconnected the timer, it still doesn’t work :frowning:

Can someone please help me?

I attach a screenshot to the timer (it is attached to a widget to display it),

This is probably fine destruction wise I’d post your respawn code that’s likely where the issue is also how do you call the respawn if the player is destroyed? Do you have a respawn manager? Or do you handle it in the level blueprint?

2 Likes

You’re destroying the controlled pawn here right? If so, that’s bad. The problem is you’re not unpossessing the pawn before you destroy it.

Unpossess, then destroy. The game mode should be handling all character spawning and possession.

End of day you should be re-using your pawns.

2 Likes

Hi ,many thanks for your kind help.
This is the death event I do have in my character BP. It was working fine earlier, besides I did create an NPC which is roaming and eventually when gets the player is destroyed as well (and this was working fine earlier).

The death event is from this template :

(I am a newbie and don’t have much idea yet)

and this is the actual respawn from the game mode BP;

(I didn’t touch any of these two, it came like this with the template)

thank you for the information, I tried to un posses it, but I am having issues with my reference (I can’t use my character BP) :frowning:

(I am a newbie and don’t have much idea yet)

We all were newbs at one time. You’ll learn as you go, just stick to it.

This is going to be a long post so bare with me.


UE is built on C++, so even though you are working with Blueprints you are still bound to the C++ paradigm. That being said you have to wrap your head around working with references, class inheritance etc.

If your controller class needs specific data about your character or wants to call an event on the class you need a reference. References are essentially pointers to the specific instance. Using Get Controlled Pawn will give you some access, but not all. You will need to cast. If you’re casting to a actor a lot you should just create a reference variable and save some resources.

When our pawn is spawned in we should be “Polling” any and all components and classes that we will be referencing often. The same applies to the controller.

Polling is the process where the computer or controlling device waits for an external device to check for it’s readiness or state.

That’s a generalized C/C++ definition, yet it’s accurate enough.

Characters aren’t possessed by controllers instantaneously. The Game mode spawns the authoritative pawn in its sim and then possession takes place. Once replicated (spawned on our screen) we can then and only then reference them.

So for example if in the controller Begin Play we get controlled pawn, cast to character class, this will generally fail. Will definitely fail in a multiplayer setting. “Access None” errors every time we try to use the reference variable. Yet by adding a delay to the begin play we give replication (networking) time to get the pawn and spawn it. This is the general ‘wide use’ hack.

Polling is the proper way.

image

Begin Play → Poll References

If the reference cannot be set on the first call of the function it will init the Polling loop.

You can add a sequence node to the function and poll many different references in a single function.


When a player dies we should technically be re-using the pawn. Unpossess it, teleport it to the spawn location, reinitialize it, then possess and go.

Regardless the approach we should restart that polling process to ensure we have up to date and accurate references.

On Death functionality should nullify the reference variable after the destroy actor node is called. Or at least have an event in the controller and elsewhere that clears them.

Simply “setting” a variable with no input will clear them.

image

Hope this was helpful.

2 Likes

It was indeed and I honestly appreciate you taking the time for such a detailed explanation. I didn’t get all the details being completely honest but I think I got the general idea and saved this on my bookmarks for future reference so I can implement the poll reference (is this a script rather than a BP? I ask as it is purple) .
I also managed to solve it using un-possess so it now works fine; again many thanks for your kind help!

Just very quick one to see if I got right; when you wrote “the controller pawn will give you some information but not at all” do you mean to the “get character” action in my screenshot, right ? (To make sure I am not mixing with any other concept)

It’s a Function.

Get Player Character, Get Controlled Pawn etc. They’ll give you base class info/access. Anything deeper you need to cast.

example…

Same applies to custom variables and functions.

1 Like

thank you very much indeed, that makes a bit more sense now :raised_hands: :raised_hands:

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