playMaker

Author Topic: ArrayList Find GameObjects Inside Collider  (Read 2058 times)

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
ArrayList Find GameObjects Inside Collider
« on: December 02, 2015, 07:43:05 AM »
Add to an array all the objects (3d or 2d) which are inside a collider. Extension to http://hutonggames.com/playmakerforum/index.php?topic=11673.0

Filter by tag (obligatory) then optionally by layer.

2 actions:
- ArrayList Find GameObjects Inside Collider
- ArrayList Find GameObjects Inside Collider2D

on ecosystem or https://snipt.net/dudebxl/
« Last Edit: December 02, 2015, 08:21:16 AM by dudebxl »

foxdeltagames

  • Junior Playmaker
  • **
  • Posts: 62
    • View Profile
Re: ArrayList Find GameObjects Inside Collider
« Reply #1 on: December 02, 2015, 11:01:26 AM »
nice! this can come in handy :)

Acavodo

  • Playmaker Newbie
  • *
  • Posts: 1
    • View Profile
Re: ArrayList Find GameObjects Inside Collider
« Reply #2 on: July 15, 2017, 03:52:47 AM »
Hi! Im trying to use this action for bomb effect.

Here's capture for my setting.


it is not finding any object which I tagged correctly.

I think "Collider Target" needs its own collider component right?

help !

omgitstri

  • Playmaker Newbie
  • *
  • Posts: 46
    • View Profile
    • My Prototypes
Re: ArrayList Find GameObjects Inside Collider
« Reply #3 on: October 16, 2017, 10:34:05 AM »
Hello,

I think I found a small bug about the action, it seems like the Root GameObject requires to have a Mesh Renderer for this action to add it to the Array List.

Right now I have a gameobject (Tile) within it I have a child gameobject (Mesh) so I could easily swap out the placeholder in the future and this is causing it to not add the Tile into the Array List.

A work-around that I'm using now is to add a MeshRenderer on the root gameobject with nothing in it so the action could detect it.

Tri Nguyen
Tri Nguyen
Game Designer at Nvizzio Creations

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 13298
  • Official Playmaker Support
    • View Profile
Re: ArrayList Find GameObjects Inside Collider
« Reply #4 on: October 16, 2017, 11:29:23 PM »
Hi,

 I checked the action and yes, it's a requirement, is that a problem for your case?

 Bye,

 Jean

omgitstri

  • Playmaker Newbie
  • *
  • Posts: 46
    • View Profile
    • My Prototypes
Re: ArrayList Find GameObjects Inside Collider
« Reply #5 on: October 17, 2017, 07:47:33 AM »
Hello,

Maybe it's just my workflow that makes me think it's a bug.
I usually have the Root contain all the scripts/FSM and have its Child be the mesh, that way i could always update the mesh whenever I want to without having to add the script/FSM again. Because of this, my Root gameobject don't have a mesh renderer and that causes the action to not work.

Tri Nguyen
Tri Nguyen
Game Designer at Nvizzio Creations

omgitstri

  • Playmaker Newbie
  • *
  • Posts: 46
    • View Profile
    • My Prototypes
Re: ArrayList Find GameObjects Inside Collider
« Reply #6 on: October 18, 2017, 09:58:55 AM »
Hello,

The action does not seem to work if it is on a prefab that gets instantiated.
I tested this by:
  • instantiating the prefab at 0,0,0 with object tagged as 'Tile' at the same location but the Play Maker Array List Proxy does not update
  • then I tried placing the prefab at 0,0,0 beforehand without instantiating and it managed to grab the objects that are tagged as 'Tile'

Tri Nguyen
Tri Nguyen
Game Designer at Nvizzio Creations

Deek

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: ArrayList Find GameObjects Inside Collider
« Reply #7 on: March 11, 2018, 08:36:59 AM »
I've created two new actions based on dudebxl's derivations to be found on the Ecosystem:
"List Game Objects Inside Collider" and "List Game Objects Inside Collider 2D".
They differ in that they rely on the target GameObjects to have Collider/Collider2D components instead of Renderer/Sprite components, the 'Collider Target' variable only allows the right component to be inserted, the 'Tag'-variable only shows the existing tags as a drop-down list instead of a string input and is set to 'Untagged' by default; they optionally store the result in an FsmArray, store the amount of entries and update every frame.

I would also propose, that the actions by dudebxl actually say that the target GameObjects need to have a Renderer component and for the 2D version a Sprite component somewhere, because they are otherwise confusing and don't seem to work if you don't know that.

krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 760
    • View Profile
    • Fat Pug Studio
Re: ArrayList Find GameObjects Inside Collider
« Reply #8 on: April 11, 2018, 12:28:24 PM »
I've created two new actions based on dudebxl's derivations to be found on the Ecosystem:
"List Game Objects Inside Collider" and "List Game Objects Inside Collider 2D".
They differ in that they rely on the target GameObjects to have Collider/Collider2D components instead of Renderer/Sprite components, the 'Collider Target' variable only allows the right component to be inserted, the 'Tag'-variable only shows the existing tags as a drop-down list instead of a string input and is set to 'Untagged' by default; they optionally store the result in an FsmArray, store the amount of entries and update every frame.

I would also propose, that the actions by dudebxl actually say that the target GameObjects need to have a Renderer component and for the 2D version a Sprite component somewhere, because they are otherwise confusing and don't seem to work if you don't know that.

Am i doing this right?



I don't seem to be getting anything :(

DanielThomas

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 65
    • View Profile
Re: ArrayList Find GameObjects Inside Collider
« Reply #9 on: April 13, 2018, 10:05:10 AM »
Just wanted to say I get the same problem as krmko, nothing shows up. Anyone who can confirm they got it to work?

Deek

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: ArrayList Find GameObjects Inside Collider
« Reply #10 on: April 13, 2018, 03:25:30 PM »
Yup, that was a mistake on my part.
In the original actions the GameObjects in the scene got searched by tag with the function "GameObject.FindGameObjectsWithTag()", which requires a tag to be specified and doesn't seem to allow the 'Untagged'-tag.
Since I naively assumed that it would just work to set the 'Untagged'-tag by default and only tested both actions with a specific tag, I didn't think 'Untagged' would cause any trouble.

I fixed this problem, which means you'd need to re-download the actions from the Ecosystem. Sorry for the inconvenience.

I also re-worked both actions to not only allow to filter by 'Untagged'-GameObjects but also made that tag filter completely optional, meaning you now can set the tag to 'None' and it ignores that tag filter, resulting in listing every GameObject regardless of the tag. The layer-filter is unaffected and can be used in conjunction with the tag-layer to narrow down, which GameObjects to capture.
Additionally, I implemented an error check when the collider target wasn't set and that when toggling the tag from 'None' to the tag-list it shows 'Untagged' instead of an empty entry (uses OnGUI so it might not always do that, but that would be just a minor inconvenience if not).


P.S.: If anyone is interested to know how any of these actions work (for clarity or performance reasons), here a short rundown:
- the action searches for each active GameObject in the scene (dudebxl's versions directly by tag, which is slightly more performant but forces you to define a tag, while mine search for any Object of type GameObject; in either case these actions should be repeated/used as scarcely as possible to reduce that overhead of constantly going through all GameObjects in the scene);
- it checks for each found GameObject if it matches the specified tag and layer;
- skips any GameObject that doesn't contain an appropriate collider component;
- gets the bounds of each collider, sees if it intersects the bounds of the user-defined collider and only lists the GameObjects that match all these criteria