Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Franck on October 10, 2018, 01:49:03 PM

Title: How to kill prefab enemy?
Post by: Franck on October 10, 2018, 01:49:03 PM
Hello everyone,

in my FPS I do a raycast to hit the NPCs. When the Prefab is in the scene everything is working properly. My raycast hits the target with a collider trigger and deal damage.
On the other hand, when I remove the prefab from the scene and instantiate it at start it's a clone that's created and my raycast does not work on it anymore, so I can not kill it.
Title: Re: How to kill prefab enemy?
Post by: djaydino on October 10, 2018, 11:06:22 PM
Hi.
Can you show your setup?

Do you use layers to filter the raycast?
Title: Re: How to kill prefab enemy?
Post by: Franck on October 12, 2018, 09:10:00 AM
Here is a video showing that Zombie Clone from prefab don't die and the zombie Prefab put in the scene is dying.

Anything else you need to diagnose?

I don't use layer to raycast, I use collider as trigger to know exactly where I'm shooting.


Edit: Zombie clone spawn thanks to an Empty Object with create object action. Zombie Prefab is just put in the scene as other objects.
Title: Re: How to kill prefab enemy?
Post by: daniellogin on October 12, 2018, 11:45:53 AM
One way to troubleshoot this situation is to; start the game, get the enemy to spawn, then (while the game is still running) go to that spawned enemy's playmaker FSM to take a look in there for what's happening. Check to make sure all variables and things being pointed to are still there and not lost somehow from it being a prefab.
Title: Re: How to kill prefab enemy?
Post by: Franck on October 12, 2018, 12:11:40 PM
Hi,

all is ok when the game start.
The problem is when the Clone spawn, my raycast search for the hit object "Zombie" but the clone has "Zombie (clone)" as name, then my raycast doesn't recognize that name because of "(clone)".
Same thing with the Pursue action. My prefab Zombie Pursue me well but not the clone. The clone doesn't recognize the player even if I set the player character from the scene or the prefab in the game object (Set as destination).

I hope I'm clear enough because I'm not English lol, I'm just a poor french guy :)
Title: Re: How to kill prefab enemy?
Post by: Franck on October 13, 2018, 09:44:31 AM
Help please :)
nobody has an idea?
Title: Re: How to kill prefab enemy?
Post by: djaydino on October 13, 2018, 02:25:49 PM
Hi,
You should use layers or tags instead of name to 'search'
In a raycast you can set layers directly
Title: Re: How to kill prefab enemy?
Post by: daniellogin on October 14, 2018, 11:39:42 PM
Hi,

all is ok when the game start.
The problem is when the Clone spawn, my raycast search for the hit object "Zombie" but the clone has "Zombie (clone)" as name, then my raycast doesn't recognize that name because of "(clone)".
Same thing with the Pursue action. My prefab Zombie Pursue me well but not the clone. The clone doesn't recognize the player even if I set the player character from the scene or the prefab in the game object (Set as destination).

I hope I'm clear enough because I'm not English lol, I'm just a poor french guy :)
Actually, unless I'm misunderstanding, I think what you are saying is that it's *not* fine when you check the FSM of the spawned enemy. It's looking for a specific gameobject called "Zombie", but that is *specific* and is the original object you turned into an FSM.

So you need to turn it dynamic one way or another. That is, pointing to what ever meets the criteria, not just a specific object.

So as the other reply said, maybe this can be done by targeting a whole layer or tag. That way no matter what gameobject it is, if it's in that criteria the action will work.
Title: Re: How to kill prefab enemy?
Post by: Franck on October 15, 2018, 11:53:14 AM
Hi,

I think the problem comes from the use of prefab. Currently I'm trying to work with "set game object" to instantiate my prefabs and give a Variable name to my Prefab.
Maybe this is the solution?

How do you instantiate your prefabs so that the variables are not lost?
Title: Re: How to kill prefab enemy?
Post by: hoyoyo80 on October 15, 2018, 07:44:23 PM
For me, i create a global gameobject variable and set it to the prefabs.
Title: Re: How to kill prefab enemy?
Post by: djaydino on October 16, 2018, 08:12:34 AM
Hi.
Not a great idea to use Globals for that :)

Maybe you can try this :

When raycasting, get the object that is hit in a variable 'EnemyHit' (for example).

Then use a tag switch or tag compare on the 'EnemyHit'.

If it has a 'Enemy' tag then you can do this (for example) :

"Set Fsm int", 'EnemyHit' (Target) , 'HitDamage' (variable) : set a certain damage you wish to give to the enemy (depending on weapon)

Then

"Send Event By Name",  'EnemyHit' (Target) , 'DoDamage' (Event)


On the Enemy have a Transition named 'DoDamage' (all enemies should have the same event name, also the event does not need to be set to global)

Deduct the 'HitDamage' and check if enemy health is 0 or below then die or not die.
Title: Re: How to kill prefab enemy?
Post by: Franck on October 16, 2018, 09:54:28 AM
Hi guys,

thx for yours replies.
But the problem also arises with the enemies who must pursue the character (me). The first clone that spawn happens to do it but not the 2nd. In the same way that I can kill the 1st but not the 2nd. It's really weird but I had to forget something I think.
Title: Re: How to kill prefab enemy?
Post by: Franck on October 16, 2018, 10:06:32 AM
Here is how I do:

1. Create Empty GO called "GameManager"
   a. Add a state with 2 "Set GO" actions:
       - Set Game Object
            Variable "PersoFPS"
            Game Object --> It's the Character, me. Drag & Drop from the scene

       - Set Game Object
            Variable "Zombie01"
            Game Object --> Prefab Drag & Drop from Project Tab

2. Create Empty GO called "SpawnZombie01"
   a. Add 2 states with:
       - State 1 with a wait 1sd and go to FINISHED
       - State 2 with Create Object
            Game Object --> Prefab Drag & Drop from Project Tab
            Spawn Point --> The Empty GO itself
            Position --> None
            Rotation --> None
            Store Object --> Zombie01

3. Duplicate the 1st GO and rename to "SpawnZombie02"
   a. Copy/Paste state from the 1st and just change the Spawn Point
Title: Re: How to kill prefab enemy?
Post by: Franck on October 16, 2018, 12:11:00 PM
If it has a 'Enemy' tag then you can do this (for example) :

"Set Fsm int", ...

How can I make this action? Set FSM and Get FSM doesn't work with prefab?
Title: Re: How to kill prefab enemy?
Post by: djaydino on October 17, 2018, 08:31:11 AM
Hi.
Get/Set Fsm should work with any object if the correct variable/fsm/gameobject is set.
I will see if i can make a video in the next few days.
Title: Re: How to kill prefab enemy?[SOLVED]
Post by: Franck on October 17, 2018, 11:19:13 AM
Thx djaydino.
For the moment I try to fix it myself. If I find something I come back here.
Title: Re: How to kill prefab enemy?
Post by: jeanfabre on October 18, 2018, 03:28:04 AM
Hi,

 GetFsmXXX and SetFsmXXX work everyframe, even if you have to manually define the fsm name and variable name, so chances are you are not referencing the fsm name and variable properly.

 Bye,

 Jean
Title: Re: How to kill prefab enemy?
Post by: Franck on October 19, 2018, 03:07:43 AM
I managed to make everything work.

Thanx to you guys ;)