playMaker

Author Topic: Prefab Cube with FSM and local variables - all instantiated prefabs are linked??  (Read 2190 times)

matthewsutherland

  • Playmaker Newbie
  • *
  • Posts: 6
Hi there. I have a scene setup with a cube prefab that is being instantiated (create object) along a grid repeatedly. When I add an FSM to the cube prefab, every action affects all instantiated prefab's game-wide. In the attached example I made a simple get position, adjust, set position on the prefab FSM. Clicking on the bottom blue cube pushes all prefab's upward, whereas I want each cube to be unique.

Am I missing something fundamental, or a limitation here?
« Last Edit: March 04, 2018, 04:58:46 AM by matthewsutherland »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Hi,
Any Changes on a prefab in the project window will affect to every same prefab object in the scene
A prefab works like that.
so if you would want certain prefabs without the fsm and some with, you should make 2 prefabs.
One with and one without.

Also i think you use the Get Mouse Button Down action?
if so, this action will trigger anywhere on the screen, not only on the object.

The transitions on the image below will work on the object, so you can use mouse down to use on your object :






matthewsutherland

  • Playmaker Newbie
  • *
  • Posts: 6
Thanks very much djaydino. I just realised when reading your post that every action I tried would have affected every instance.. stuuuupid

Thanks again!!

daniellogin

  • Full Member
  • ***
  • Posts: 215
I had a similar problem.

I am using Emerald AI in a prefab to make enemies move and shoot. I created my own actions which removes the enemies when they collide with my projectile, but also creates objects from the same prefab to replace the enemy killed. All of the actions were in the prefab.

The problem was that the replacement AI didn't work properly. At first I thought it was to do with the AI and other things I was doing (outside of the normal AI functions) but I then realised that using and FSM in a prefab to create object the same prefab seemed to transfer information. Changes I made to the actively placed object were not reset when it created the prefab again. It even called the placed objects "(clone)", instead of "(1)" etc. 

The solution to my problem was to simply move the create object action from prefab to an FSM outside of the prefab.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Hi.
just a notice, if you reuse prefab several times you should pool them.
Creating and destroying object is expensive and leaves garbage.

you can find a pool system on the Ecosystem Called Pooler

daniellogin

  • Full Member
  • ***
  • Posts: 215
Hi.
just a notice, if you reuse prefab several times you should pool them.
Creating and destroying object is expensive and leaves garbage.

you can find a pool system on the Ecosystem Called Pooler
Thanks, I'll look into that now.