PlayMaker Updates & Downloads > Share New Actions

ArrayList Find GameObjects Inside Collider

<< < (3/4) > >>

Deek:
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

agelvik:

--- Quote from: Deek on March 11, 2018, 11: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.

--- End quote ---

Hey,
The script works well except when the collider gets rotated.

Seems like the action doesn't list objects accurately when it's rotated which results in undesired results... Instead of listing objects according to the colliders shape, it translates to this square shape and list objects that are expected to be outside of it.
I'm using "List Game Objects Inside Collider" btw, don't know if same applies to the 2D version

Would be awesome if this could get fixed!

Deek:
@agelvik

Yea..., apparently the Bounds.Intersects() method I used in both actions doesn't play nicely with rotated objects since it uses the root rotation instead of the local one. You can actually find a few posts on the Unity forum mentioning this behavior, but it seems to be like that by design.
I've found a few possible solutions involving Raycasting to detect overlapping areas, so I will try to implement them on the weekend.
If one of them work, I either replace the current behavior or add a checkbox to use the Raycast version for detecting rotated objects accurately, as it is usually less efficient. I also remember creating a script that checks if NGUI sprites are in view by using the camera's frustum, so that might also be an option for this.

I didn't know of this behavior so thanks for pointing it out and I'll see if I can find a fix or better solution for that.

agelvik:
Much appreciated, thanks!!

Deek:
I now improved both versions to more accurately detect colliding GameObjects even with a rotated source GameObject. The 2D version is way more accurate in regard to box colliders, since it uses a built-in function for detecting overlapping colliders and on the 3D version I had to manually adjust the extents of the collider, which means that there can still be a small gap between two colliders in which the second one gets recognized (and judging by your screenshot, you probably should use 2D colliders anyway  ::)).
Each should be a bit more performant, because they don't go through each GameObject in the scene anymore. On top of that, I also added a filter to ignore triggers and removed the "Incl Layer Filter" checkbox by making the Layer field start as 'None', as well as other minor improvements.

They have been updated in the Ecosystem and are also available in the attachments.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version