I have an actor (Ball) that is getting reattached from character to character (Players) and I have an enemy actor (dog) that is detaching the ball from player, attaching it to itself and kills the character afterwards.
But when the player is getting destroyed the ball that is no longer attached to him also getting destroyed. (I want the ball to stay alive)
Everything else works fine when I test the sequence without destroying the player.
when the player is getting destroyed the ball that is no longer attached to him also getting destroyed.
Could you explain / show how the ball actor gets into the game?
(post deleted by author)
It’s getting spawned by invisible actor called “Ball spawner”
- how does the
Ball Spawner
get into the game? - how is the ownership of both actors set up (in case you set it up)
The Ball spawner is located in the level from the start and is the owner of the ball because it spawns the ball. I don’t set up the owndership in other way.
I just tried to set the ownership to the actor it attaches to, but it changed nothing.
This is not a standard behaviour, but I tested it in a clean project, just in case:
- spawn an actor
- attach to a Pawn
- destroy Pawn
- the spawned actor stays
You do not even need to detach it.
There has to be something else we do not know about your setup. Post relevant script if all else fails. In order to actually destroy the attached actor, the actor would need to look it up, and explicitly destroy it:
The Ball spawner is located in the level from the start and is the owner of the ball because it spawns the ball
How is this done? Because I can imagine a scenario where the Spawner could set class on the Pawn’s Child Actor Component
. In this case, destroying the actor would take down the CAC and the child actor whose lifecycle it maintains.
Again, the more detail you can provide the better; this in uncanny and we know too little atm.
Ok, thanks, I’ll try to search for the problem somewhere else.
Ye I understand. But there’s nothing more I could think of. The Ball is getting spawned by the spawner, then it finds the nearest player, moves to it and attaches trhough the “Attach to component”(I need it to specify the bone) node, sets it’s owner to the pawn it just attached to.
The fact that it’s not a normal behaviour helps itself. I’ll continue to search for the problem knowing that it’s not the attach/detach logic problem
Just checked this:
I throw ball to another player and the dog kills it’s previous owner. This way the ball is not getting destroyed. It means that problem is only with destroying the pawn that already holds the ball and getting destroyed.
The problem was that player controller had the “controlled ball” variable that was set when the ball attached to the controlled pawn.
As I set to the controlled ball to “none” on ball detachment the problem got fixed.
Aaaand it was finally my code that destroyed the ball with the player (in the case player dies in other way then from the dog), hidden very deeply XD