playMaker

Author Topic: Creating a prefab with targets/variables intact  (Read 11961 times)

cmart

  • Playmaker Newbie
  • *
  • Posts: 3
Creating a prefab with targets/variables intact
« on: August 07, 2012, 03:44:07 PM »
Hi folks, I am hoping someone can help me out with a problem I am having. Basically, I want to create a prefab that retains EVERYTHING I set up in playmaker. For instance, I have an enemy with some basic A.I. and player tracking FSMs, and when I duplicate the object in the hierarchy, it works like a charm, all the playmaker stuff works great. But when I try to to take the same object and drag it into a prefab, it copies the majority of the playmaker info but looses all the game object targets and resets (some, but not all, for whatever reason) variables etc.

This is giving me such a headache! It seems simple enough, but I can't figure it out  ???

thanks for any help!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Creating a prefab with targets/variables intact
« Reply #1 on: August 08, 2012, 05:16:18 AM »
Hi,

 you won't be able to retain gameObject references form the scene. That's a limitation in Unity. Now if you loose other variable types values, you should submit a bug to playmaker.

bye,

 Jean

cmart

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Creating a prefab with targets/variables intact
« Reply #2 on: August 08, 2012, 03:16:19 PM »
Hi,

 you won't be able to retain gameObject references form the scene. That's a limitation in Unity. Now if you loose other variable types values, you should submit a bug to playmaker.

bye,

 Jean

Ah, bummer. Thanks for the reply though, not exactly the news I wanted but it is nice to have a definitive answer.

This is more of a general Unity question I thought I might ask while I am here, is there a way to drag a duplicate of an object from the hierarchy into a scene (like you would a prefab from the project explorer). I know you can drag a duplicate from within the scene (control+D) but I have a huge level and there aren't always the object I need to duplicate near by, it would be much easier to drag from the hierarchy..

thanks!


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Creating a prefab with targets/variables intact
« Reply #3 on: August 09, 2012, 03:12:08 AM »
Hi,

Yes, prefab instanciation is not really ideal when you start building dense worlds. I have seen projects where several duplicated prefabs with different settings are stored, so if you have for example the same prefab but with three different major variation, drag them back to the project folder as new prefabs.

does that make sense?

bye,

 Jean

Sobek

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Creating a prefab with targets/variables intact
« Reply #4 on: September 18, 2012, 03:50:08 PM »
Hi

Im having the same kind of problem. I have build up a scene with a player, health_manager, ammo_manager, enemies, bullets etc. It all works perfect.
When the enemies find the player they shoot and decrese his health.
So i made a prefab of the enemie, and a FSM script to tell when and were the prefabs of the enemie will be spawned. And they do spawn. But there FSM script has forgot most of the gameobjects and all variabels they were told to interact with.

I solved there loss of gameobject by simply make a prefab of each gameobject that interact with the enemie, and drag droped each of them into the enemie prefab FSM trought the project panel. So no it dont forget the gameobjects, witch it does if they are drag droped from the hierachy  panel.

But i cant solve it with the variabels sense i cant turn them into prefabs :)

Another thing that is extremly frustating is that when the enemie prefab is shooting at the player, its FSM send a messegae to another FSM within the health_manager and tells it to fire of a dec health event (lower players health), only problem is that the health manager wont fire of the event, even tou its told to do so. If i then replace the prefab with the exact same enmie but not a prefab, it all works great.

i also get this error/ warning (yellow icon) message while run the scene:

 DebugFlow: Missing Cached Variables...
UnityEngine.Debug:LogWarning(Object)
HutongGames.PlayMakerEditor.DebugFlow:Stop()
HutongGames.PlayMakerEditor.FsmEditor:PlaymodeChanged()
UnityEditor.Toolbar:OnGUI()   

Does anyone know how i can get pass this? somehow i have to. I mean i can not possible add 64 enimies at once to each scene, i need prefabs. :/

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Creating a prefab with targets/variables intact
« Reply #5 on: September 24, 2012, 03:18:22 AM »
Hi,

prefab CAN NOT keep reference of gameObjects in the scene when they are not instanciated.

 for this you can use global variables to store a reference to a gameObject and then use that variable within a prefab to get to it.

 this restricition is a Unity restriction, not a playmaker on.

 bye,

 Jean

hipoh

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Creating a prefab with targets/variables intact
« Reply #6 on: November 19, 2013, 06:20:10 AM »
is there a better answer/explanation on how to handle this?

Been struggling for a few days now :-(

So i have a nav store, which creates an array of all the nav way points in a level.

A bot looks for the nearest waypoint and goes there.. when it hits a nav point that nav point tells it the location of the next one.

Some of these relationships are lost when saving as a prefab (as stated above).


So can you please help by explaining the best way of doing this so the data is saved in the prefab and therefore transferable?

Ideally id like to sub divide the array based on parent/children and use that system for accessing all variables/data. So the array will be used to access and update game objects .. (im not sure how to do that either really not a coer, using FSM)

Yanifska

  • Full Member
  • ***
  • Posts: 163
    • My Portfolio
Re: Creating a prefab with targets/variables intact
« Reply #7 on: November 19, 2013, 06:44:39 AM »
I do find gameobject with tag in the start state in each prefab so they have a reference to the obejct they need to interact with
Visit my portfolio: http://www.yanivcahoua.com/

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Creating a prefab with targets/variables intact
« Reply #8 on: November 19, 2013, 07:36:50 AM »
is there a better answer/explanation on how to handle this?

Been struggling for a few days now :-(

So i have a nav store, which creates an array of all the nav way points in a level.

A bot looks for the nearest waypoint and goes there.. when it hits a nav point that nav point tells it the location of the next one.

Some of these relationships are lost when saving as a prefab (as stated above).


So can you please help by explaining the best way of doing this so the data is saved in the prefab and therefore transferable?

Do something at runtime that identifies the objects, if the Agent is able to be given, take, or read information between a waypoint then you can set it up so that you fill that information at runtime and it can be designed to work entirely locally to that Agent in a prefab.

For instance, if you use a collider to trigger that he is going to the next waypoint then just store the collider (Agent) and send information to it when there is a collision. Such as the next waypoint variable. You wouldn't even need to change anything on the agent, just change a variable that it is always using locally. Create a Destination variable (that is obviously empty, since the Agent is a prefab) and put that into your locomotion as a destination and fill it at runtime.

That is typical. By designing smarter behavior for objects and systems you can have more prefabs that are significantly more flexible and modular.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

nighty9

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Creating a prefab with targets/variables intact
« Reply #9 on: November 12, 2014, 04:23:05 AM »
What i do is using a get parent/child, and store it in a variable that i then use to set the gameobject, if it's further i use then a 'set fsm gameobject' action to set the variable locally where i want it to be, avoiding the global variables at maximum so you don't get any conflict while having multiple scripts setting up the same global variable.

Works like a charm for me :)