playMaker

Author Topic: Prefab to 'see' game object in scene.  (Read 1000 times)

curb47

  • Sr. Member
  • ****
  • Posts: 256
Prefab to 'see' game object in scene.
« on: September 27, 2020, 10:40:54 AM »
Hi there,

I'm trying to streamline my logic, and I have an enemy floating alien (rigid body, physics) that uses the Look At (game object - player spaceship) action, with Add Force so it moves towards to player spaceship.

I've turned the enemy alien thing into a prefab and I'm using a pool to spawn them at certain trigger points, however, when the pooled clone is spawned, the Look At action no longer has the game object - player spaceship parameter.

I've looked into it, and am I right in understanding that a prefab can not 'see' a gameobject, prior to spawning? Like, you can't reference a game object from the scene in an action on a prefab?

I've tried using game object variables too, but nothing seems to work.

Does this make sense?

Many thanks,

J.

heavygunner

  • Sr. Member
  • ****
  • Posts: 344
Re: Prefab to 'see' game object in scene.
« Reply #1 on: September 27, 2020, 10:59:04 PM »
Yu can put scene objects on prefab. You have to use variable to set it.
What i usually do is, Use "get Owner" action and save Player prefab on global variable. then, mention that variable in prefabs

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Prefab to 'see' game object in scene.
« Reply #2 on: September 28, 2020, 06:19:28 AM »
Hi.
after you spawn a prefab you can use 'Set Fsm' actions to set data on the prefab.

For example if the spawned prefab would be a enemy and it would need to reference the player.

Then After spawning (store the spawned object in a variable)
Use 'Set Fsm Game Object' and target the spawned object.
and as variable set the Player gameobject to the target variable.

Maybe this video can help :


curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Prefab to 'see' game object in scene.
« Reply #3 on: September 28, 2020, 09:13:42 AM »
Thank you, that's perfect info!