playMaker

Author Topic: How to kill prefab enemy?  (Read 150 times)

Franck

  • Playmaker Newbie
  • *
  • Posts: 39
    • View Profile
How to kill prefab enemy?
« on: October 10, 2018, 10:49:03 AM »
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.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3504
    • View Profile
    • jinxtergames
Re: How to kill prefab enemy?
« Reply #1 on: October 10, 2018, 08:06:22 PM »
Hi.
Can you show your setup?

Do you use layers to filter the raycast?

Franck

  • Playmaker Newbie
  • *
  • Posts: 39
    • View Profile
Re: How to kill prefab enemy?
« Reply #2 on: October 12, 2018, 06: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.

https://youtu.be/x3qUZubLJm0

Edit: Zombie clone spawn thanks to an Empty Object with create object action. Zombie Prefab is just put in the scene as other objects.
« Last Edit: October 12, 2018, 06:12:08 AM by Franck »

daniellogin

  • Junior Playmaker
  • **
  • Posts: 60
    • View Profile
Re: How to kill prefab enemy?
« Reply #3 on: October 12, 2018, 08: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.

Franck

  • Playmaker Newbie
  • *
  • Posts: 39
    • View Profile
Re: How to kill prefab enemy?
« Reply #4 on: October 12, 2018, 09:11:40 AM »
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 :)
« Last Edit: October 12, 2018, 09:23:12 AM by Franck »

Franck

  • Playmaker Newbie
  • *
  • Posts: 39
    • View Profile
Re: How to kill prefab enemy?
« Reply #5 on: October 13, 2018, 06:44:31 AM »
Help please :)
nobody has an idea?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3504
    • View Profile
    • jinxtergames
Re: How to kill prefab enemy?
« Reply #6 on: October 13, 2018, 11:25:49 AM »
Hi,
You should use layers or tags instead of name to 'search'
In a raycast you can set layers directly

daniellogin

  • Junior Playmaker
  • **
  • Posts: 60
    • View Profile
Re: How to kill prefab enemy?
« Reply #7 on: October 14, 2018, 08: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.

Franck

  • Playmaker Newbie
  • *
  • Posts: 39
    • View Profile
Re: How to kill prefab enemy?
« Reply #8 on: October 15, 2018, 08: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?

hoyoyo80

  • Playmaker Newbie
  • *
  • Posts: 26
    • View Profile
Re: How to kill prefab enemy?
« Reply #9 on: October 15, 2018, 04:44:23 PM »
For me, i create a global gameobject variable and set it to the prefabs.