playMaker

Author Topic: Add Component - Problem: Component affects all Objects  (Read 2121 times)

Farwest

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 63
Add Component - Problem: Component affects all Objects
« on: February 22, 2018, 08:00:53 PM »
I have a "Falling Ground" with tiles in a room. Some tiles fall down, some don't. Therefore Player needs to carefully step.

In order to do that, I use Triggers on each Tile, so as Player moves on Triggers, tiles start to fall. On this job, I prefered to use "Add Component: Rigidbody".



Before this, when I used "Destroy Object" or "Destroy Component" by choosing my Floor tile, only ONE single tile was destroyed on-trigger, which a tile is parent object of the Trigger object.



However, in "Activate Component", when Player trigger the tile and Rigidbody Component is added, not that Single Tile gets Rigidbody, but all tiles get Rigidbody and everything falls down. This is the thing that creates complication.

What could be the problem, do you have any advice? Thanks!

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Add Component - Problem: Component affects all Objects
« Reply #1 on: February 23, 2018, 02:24:30 AM »
Why don't you try something like this, make all tiles with disabled rigidbodies and simply enable rigidbody on the tile you want to fall.

One more thing, use reference to your instantiated object, not the prefab itself.
Available for Playmaker work

Farwest

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 63
Re: Add Component - Problem: Component affects all Objects
« Reply #2 on: February 23, 2018, 08:18:10 AM »
I do exactly same like you suggested. Maybe I didn't explain it well in my question. Thus, tiles-to-be-fallen are chosen Randomly at the time Player moves on them, so there is a chance if that tile is selected to fall or not. 

To do that (if somebody is also looking for how to choose which tiles get such random "Event" let me share) I use this FSM:


About second half of your question, whether instantiated object and prefab, that is my problem it seems. In my project, tiles are generated randomly at each time, so I don't have any way to choose instantiated object, but I have to choose prefab. 

The interesting thing is, when I use "Destroy Object" or "Destroy Component", they always affect the tile Player stepped (I choose prefab in Editor). But when I use "Add Component: Rigidbody" for floor, it affects all tiles instantly, regardless I stepped on them or not.

Is there any better way to handle this problem? What do you think?

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Add Component - Problem: Component affects all Objects
« Reply #3 on: February 23, 2018, 01:03:56 PM »
That one's easy actually. Whenever you generate a tile, put it into an array, you can store it as whatever data type you like. When you want to add or destroy something, reference a random game object from array as it stores tile INSTANCES not a PREFAB.
Available for Playmaker work

Farwest

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 63
Re: Add Component - Problem: Component affects all Objects
« Reply #4 on: February 23, 2018, 01:36:38 PM »
But that is not easy for me, because I use a ready generation script of a larger game template, what I do is I am improving the gameplay by minor modifications with Playmaker actions/scripts. At the moment I don't know how to generate a dungeon system and rooms with Playmaker alone.

I hope I can find an easier way or solution for me. Thank you.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Add Component - Problem: Component affects all Objects
« Reply #5 on: February 23, 2018, 02:38:52 PM »
That's not a big issue. I presume all tiles are generated with a generic name, something like "tile x", you can find game objects containing string " tile" and then add them to an array and do the rest.
Available for Playmaker work