playMaker

Author Topic: [SOLVED]Question on > Prefabs should not reference scene objects, only other....  (Read 12097 times)

tofusoup

  • Playmaker Newbie
  • *
  • Posts: 30
"Prefabs should not reference scene objects, only other prefabs and project resources.  References to scene objects will be lost on save/load!"  Sounds bad....

So I have enemies that are prefabs.  I spawn them using poolmanager2.  For now I just have them use simple move (character controller) with smooth look at to follow the player.

When I ran this on iOS the game crashed, and I lost all the links in my fsm where it pointed to my player.  To fix this I now have a game startup FSM, where I use "Get Property" on my player and store it in a global game object variable.

Then in my enemy prefab I tell it to look at that global game object var.  The game now runs fine, but I get the above error.

So I guess I just need to make my player a prefab?  I'm kinda confused by this because the player will always be int he scene, so it doesn't need to be a prefab...or does it

any ideas?  I don't seem to understand some fundamental workflow here.  Thanks in advance.

« Last Edit: March 18, 2013, 08:54:10 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Question on > Prefabs should not reference scene objects, only other....
« Reply #1 on: January 28, 2013, 01:07:32 AM »
Hi,

 the odd thing here is that the behavior on IOS should be reproduceable within the editor. Do you run the profiler when running on IOS, and what xcode is saying about the crash? or it is "crashing" within your game but not actually shutting down the application?

Prefab or not, this is not going to solve referencing from one object to another during runtime, reference to other objects in the scene outside the prefab hierarchy is only a restriction for the prefab that sits in the asset folder.

so when you instantiate a prefab, this is when you need to either pass it the reference to the gameObject you want that prefab to be aware or have the prefab itself look for all the thing it needs on the scene.

using a global var to reference your main character is a good way to do this, all your ennemies prefab simply use this global var, this is fine.

bye,

 Jean


tofusoup

  • Playmaker Newbie
  • *
  • Posts: 30
Re: Question on > Prefabs should not reference scene objects, only other....
« Reply #2 on: January 30, 2013, 05:11:40 PM »
Yea you're right, it wasn't a crash.  When I build to iOS it complained about how I was referencing scene objects and the link was lost.  The game ran but since the link was broken my enemies didn't function properly.  But when I run my game from Unity I didn't seem to have that issue....or I need to double check.

I also thought at first it was the order how things were being loaded into the scene..so I made a startup FSM to make sure enemies and other things load a bit later.

Well either way I now use the global var game object to grab the player.

Though seeing those red (!) about the error bugs me a bit heh, but if you say this is correct I'll just ignore them.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Question on > Prefabs should not reference scene objects, only other....
« Reply #3 on: January 31, 2013, 12:29:16 AM »
Hi,

 what do you mean red bug? using global vars should not throw any errors at all.

bye,

 Jean

tofusoup

  • Playmaker Newbie
  • *
  • Posts: 30
Re: Question on > Prefabs should not reference scene objects, only other....
« Reply #4 on: January 31, 2013, 04:19:10 PM »
Here's 3 images from my project.

I get the error after I stop running my game. 

1. The error
2. The FSM that the error is reporting on
3. The FSM where I get the reference to my player


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Question on > Prefabs should not reference scene objects, only other....
« Reply #5 on: February 08, 2013, 02:36:59 AM »
Hi,

 that's odd, are you sure you haven't got a left over local variable on this prefab? you might now reference globals only, but your fsm might simply have a gameObject local variable pointing to a scene object.

bye,

 Jean

Krileon

  • Full Member
  • ***
  • Posts: 107
Re: Question on > Prefabs should not reference scene objects, only other....
« Reply #6 on: February 09, 2013, 11:31:16 AM »
I'm getting a lot of the same errors. I'm using Find Game Object then storing it to a global then using that global in a prefab FSM. Why is this occurring and how do I shut it up? It works perfectly fine. Even using "Enable FSM" and setting "Game Object" to "Use Owner" throws this error. It's very annoying and unjustified. The Prefab (owner) is of course going to exist. Only PlayMaker debugger does this and only when entering the editor again after stopping play mode.

Krileon

  • Full Member
  • ***
  • Posts: 107
Re: Question on > Prefabs should not reference scene objects, only other....
« Reply #7 on: February 10, 2013, 12:14:24 PM »
Quote
I'm getting a lot of the same errors. I'm using Find Game Object then storing it to a global then using that global in a prefab FSM. Why is this occurring and how do I shut it up? It works perfectly fine. Even using "Enable FSM" and setting "Game Object" to "Use Owner" throws this error. It's very annoying and unjustified. The Prefab (owner) is of course going to exist. Only PlayMaker debugger does this and only when entering the editor again after stopping play mode.
No suggestions? I'm getting slammed with over 30 invalid errors regarding this. Should I set the global inside the prefab instead of in a setup FSM (single FSM that establishes the globals). Even if I did that the FSMs using "Use Owner" throw the same error when used on a prefab. Again, the game and the FSMs work perfectly fine. It's just PlayMaker throwing this error.
« Last Edit: February 10, 2013, 12:17:35 PM by Krileon »

Krileon

  • Full Member
  • ***
  • Posts: 107
Re: Question on > Prefabs should not reference scene objects, only other....
« Reply #8 on: February 10, 2013, 02:10:13 PM »
Found a way to disable the error check for this. Go to Preferences in PlayMaker then in the dropdown select Error Checking and then uncheck "Check for Prefab Restrictions".

Krileon

  • Full Member
  • ***
  • Posts: 107
Re: Question on > Prefabs should not reference scene objects, only other....
« Reply #9 on: February 10, 2013, 04:07:07 PM »
Opted for an alternative approach. At the beginning of each prefabs FSM for the START state I setup local variables for the FSM using Find Game Object, etc.. then never return to that state (have an Idle state attached to FINISHED event). Performance seams fine as those calls happen during load time.. so all is good now!