playMaker

Author Topic: Get X Closest GameObjects  (Read 7380 times)

bfd

  • Playmaker Newbie
  • *
  • Posts: 21
Get X Closest GameObjects
« on: September 17, 2014, 05:04:57 AM »
I've been using the Get Closest 2 update from Ecosystem, and the ability to filter by tag is very handy. I could really use a version of this action that allows me to get more than 1 item on each pass.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get X Closest GameObjects
« Reply #1 on: September 18, 2014, 09:41:46 AM »
Hi,
 
ArrayMaker has this for you already :) use the action "ArrayListGetClosestGameObject" or "ArrayListGetClosestGameObjectInSight".

Bye,

 Jean

bfd

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Get X Closest GameObjects
« Reply #2 on: September 18, 2014, 05:32:18 PM »
Hi Jean,

I've been using ArrayMaker a bit already and it's great! Forgive me if I'm not seeing the option for returning multiple GameObjects, but the ArrayListGetClosestGameObject action seems to only return the single closest object the same way Get Closest and Get Closest 2 do.

From what I can tell ArrayListGetClosestGameObject doesn't include an option to filter by tag either like the 'Get Closest 2' action from the Ecosystem.

I may be missing something obvious, and if I am I apologise in advance, but I can't seem to see how I can use this action to return multiple items.

Edit: Just to clarify what I'm trying to do, I want to be able to set X as an integer (either manually or through variable) and then return the X GameObjects which are the closest to the target filtered by tag. So if I set X to 5 the action will store the 5 GameObjects with a particular tag that are closest to the target.
« Last Edit: September 18, 2014, 05:35:34 PM by bfd »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get X Closest GameObjects
« Reply #3 on: October 15, 2014, 01:35:55 AM »
Hi,

 ok, give me few more days, can you bump me early next week? thanks for your patience, the last 2 weeks where totally off work, sorry about that, it wasn't planned nor intentional :)


Bye,

 Jean

bfd

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Get X Closest GameObjects
« Reply #4 on: October 22, 2014, 05:29:06 PM »
Hi Jean,

I got distracted myself and missed this reply - luckily I only missed the 'scheduled bumping' by a couple of days :)

Cheers,

Steve

app_advisory

  • Junior Playmaker
  • **
  • Posts: 80
    • App Advisory
Re: Get X Closest GameObjects
« Reply #5 on: October 24, 2014, 12:56:19 PM »
Waiting for it too :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get X Closest GameObjects
« Reply #6 on: October 28, 2014, 02:04:34 AM »
Hi,

 I looked at this and I think the following could be a good way out.

since you are pooling from an arrayList, remove the gameobject that was returned by the action and perform this action the number of times you need.

 I do that quite often, use a duplicated arrayList if you don't want to loose the original list.

what I think should be done here instead could be an action that sorts an arraylist based on distance from a point. what do you think? I feel that doing a custom action to return a number of closest gameobject is not really the best way to go here.


as for tags, I added this in my todo on trello, but again I woudl suggest you work on a copy of the array and remove beforhand all the gameobjects you don't want, basically this action assumes your arrayList is already filled with valid gameobjects, tho I understand the need for flexibility to filter further within the action. So I'll add it soon when I will have my next session on arrayMaker update.

Bye,

 Jean

bfd

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Get X Closest GameObjects
« Reply #7 on: October 28, 2014, 02:25:50 PM »
Hi Jean,

Thanks for the suggestion, it's definitely an interesting way to approach my requirements and I can see how it would work but I would be concerned that approach might create an unnecessary drain on resources.

For example if I have 50+ objects with a certain tag (I'm working with a large scene) and I only want to interact with the 5 closest. That's 45 arraylist entries that need to be removed one by one before the result will be the arraylist I'm after. I don't completely understand how the back end of Unity works but I would assume that would be putting unnecessary demand on the system.

But to be completely honest, being able to sort an arraylist by distance would be an incredibly handy tool as well!

Cheers

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get X Closest GameObjects
« Reply #8 on: November 27, 2014, 01:31:26 AM »
Hi,

 Arrays work very fast, you should not be worries about this at this point. the typical process woudl be to make something that works, profile and move on if it's good, else optimize.

 I have a sample in ArrayMaker dealing with 40 000 items in an array and it's a brease.

 you'll also see that in ArrayMaker I have sample doing exactly this hiliting the closest objects from a point, and it's all done manually and it works well.

also, I have a set of new actions that's coming as soon as 1.8 is out:
ArrayListGetClosestGameObjectInSight. That action will likely be a goof fit for your needs.



 Bye,

 Jean

bfd

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Get X Closest GameObjects
« Reply #9 on: December 06, 2014, 12:17:40 AM »
Thanks Jean, the more I use Array Lists I can definitely see how quick they are. I saw you mention in another post some of the built-in Array features in 1.8 - can't wait to give it a try!

Cheers

mweyna

  • Full Member
  • ***
  • Posts: 242
Re: Get X Closest GameObjects
« Reply #10 on: April 06, 2015, 02:26:43 AM »
Was this action ever created? I have the perfect need for an array sort by distance.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get X Closest GameObjects
« Reply #11 on: April 28, 2015, 04:18:17 AM »
Hi,

 yep, the action is available in the package.

 Bye,

 Jean