playMaker

Author Topic: Use a game object from a prefab?  (Read 1556 times)

Ectobit

  • Playmaker Newbie
  • *
  • Posts: 1
Use a game object from a prefab?
« on: April 05, 2018, 10:25:19 PM »
Hey, I'm kind of a newb, so here's my newbie question:

In my current project, my player is a prefab. In the fsm controlling it, there are several times in which the player's fsm will access a game object in the scene.
For example, when the player dies, the screen flashes. This only works because I've told the fsm to animate a screen overlay using animator play. I tell it to use a specified object, and select the overlay in the scene. (The overlay is not a part of the player prefab.)

My question is:
Every time I make a change to the prefab, I have to manually go in to each scene and specify which object the player fsm needs to animate. This is going to get a bit annoying when I've got 50 levels.

Is there a way to preemptively tell the prefab fsm which gameobject it should look for?
Any help on this would make my day, as this has been causing me quite a headache.

Thanks!

 


Pyremind

  • Playmaker Newbie
  • *
  • Posts: 14
Re: Use a game object from a prefab?
« Reply #1 on: April 07, 2018, 06:27:13 AM »
Hi, I'm a newb too but I think I understand what you're asking.

So I think you want to update your Player FSM, and have it update across any new instance of the Player that might get made. If you go to the upper right of the inspector panel for your player, there's a button that says apply - this will 'apply' your change to every instance of that fab. Hope that helps.

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: Use a game object from a prefab?
« Reply #2 on: April 07, 2018, 10:40:51 AM »
Hi, so prefabs and templates cannot directly access scene objects as you have noticed. Also, usually, its not a good idea to have the player itself as a prefab. Instead, you may want to use a 'dont destroy on load' approach, which will keep the same game object alive between scenes. There is a playmaker action for that. This would likely solve many of your problems.

Only use a prefab if you really have a reason to do so.

Also, you can make a manager for each scene if you want. Give it the same name in each scene. Like "manager". Then your player can find game object by name called "manager", and get all the variables necessary from it. You should use find game object by name often, but doing it once on a scene load is not a problem.

Make sure to learn about using global events and get fsm actions (get fsm gameobject, etc). So you can get the variables you need from your manager.