playMaker

Author Topic: Prefab problem: error message 'required field...' keeps returning [SOLVED]  (Read 1591 times)

Andreas Tabak

  • Playmaker Newbie
  • *
  • Posts: 9
Hi everybody,

I'm still a bit confused how Playmaker works with Unity prefabs it seems. I'll try to explain my problem the best I can.

I have a simple scene, with a floor, a player and one enemy. As soon as the enemy is hit it should die (and before some gory fun) for which I use some FSM. Now to add more of the same enemies, I turned the enemy into a prefab.

Now the fun starts. The error check shows me that there are 4 errors. If I click on the errors it opens the prefab and the FSM to show the actions that are in error. These are references to objects outside of the prefab like the camera or some blood-spatter PNG's that are in the canvas. The prefab starts by saying there are 4 errors, but as soon as I open the errors they become eight. Then I fix them, but it still remains on 4 errors. If I click on the errors again it opens the same prefab I just fixed but with the same errors back again.

If I run the game with the errors nothing happens and the game runs perfectly including the actions that are in error.

So what am I doing wrong exactly? Thanks for your help :-D
« Last Edit: February 02, 2019, 02:17:23 PM by Alex Chouls »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Prefab problem: error message 'required field...' keeps returning
« Reply #1 on: February 02, 2019, 09:04:21 AM »
Prefabs can't store references to scene objects. This is a Unity, not PlayMaker specific restriction. It may seem like you can "fix" these errors by re-adding the scene references, but Unity will not save them when you exit the project.

Instead, you need to initialize the scene object references in your scene Instance of the prefab. There are a couple of ways to do this:

1. Use a variable for the scene object reference and check Inspector in the Variables manager. This will expose the variable in the PlayMakerFSM inspector. Select the instance in the scene and set the exposed variable to a scene object.

2. Use actions to find and store scene objects. E.g., GetMainCamera, or Find GameObject.

The first method works well if you are instantiating prefabs at edit time, and can set them up in the scene. The second works if you're instantiating prefabs at runtime and the instance has to set itself up.

Does that help?

Andreas Tabak

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Prefab problem: error message 'required field...' keeps returning
« Reply #2 on: February 02, 2019, 10:01:18 AM »
Wow Alex, that is one quick response! Thank you very much for your time and answer. I am a total n00b but I think I get the solution you propose. Thanks!

Andreas Tabak

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Prefab problem: error message 'required field...' keeps returning
« Reply #3 on: February 02, 2019, 10:54:43 AM »
Sorry to bother you once more. But I got the camera working, unfortunately making the gameobjects activated again is another thing. I'm doing something wrong but I don't know what exactly. So my question is how do you assign variables to scene instances? Do you have to attach a FSM to the scene instance and use 'set FSM variable' action to give it the desired global variable? Or am I missing something?

Thanks in advance!

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Prefab problem: error message 'required field...' keeps returning
« Reply #4 on: February 02, 2019, 12:56:14 PM »
First add a GameObject variable in the prefab FSM, e.g., ActivateGameObject.
Use that variable in your FSM instead of references to scene objects.
Select that variable in the Variables tab and check Inspector.
You should now see an ActivateGameObject field in the FSM tab or PlayMakerFSM Inspector under Controls.
Select a scene instance of the prefab and you can assign a scene GameObject to that control.

Alternatively, use a naming convention or tag and the Find GameObject action to find the GameObjects to activate.

Andreas Tabak

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Prefab problem: error message 'required field...' keeps returning
« Reply #5 on: February 02, 2019, 01:41:23 PM »
Wow! Thanks again for the quick reply and your great answer. I got everything working now like a charm.

Just goes to show I still have a great deal to learn about the power of Playmaker.

Thanks!

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Prefab problem: error message 'required field...' keeps returning
« Reply #6 on: February 02, 2019, 02:17:11 PM »
Glad you got it working! :)