playMaker

Author Topic: [SOLVED] Having a problem with Find Closest  (Read 3794 times)

jwvanderbeck

  • Playmaker Newbie
  • *
  • Posts: 18
[SOLVED] Having a problem with Find Closest
« on: December 10, 2014, 10:10:35 PM »
I am working on a spawn system for a galaxy.  Right now I am just doing something very simple.  I spawn a Star.  Then I use Find Closest to find the nearest Star.  If that distance is above or below a threshold I set the material on that Star to be a color that signifies it is invalid.

The problem is Find Closest doesn't seem to be working properly.  I correctly flag all the stars that are above the threshold, but none of the stars below the threshold.  Even stars sitting so close together that the meshes penetrate each other don't get flagged.

I don't know if Templates work the way I think they do, but assuming they do, i'm attaching the FSM template to this post to show what I am doing.
« Last Edit: December 11, 2014, 08:53:02 AM by Lane »

jwvanderbeck

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Having a problem with Find Closest
« Reply #1 on: December 10, 2014, 10:15:06 PM »
Ok playing with this some more, and it looks like because these spawned objects are all clones of one object, PlayMaker is ignoring them all as if they are the same object.  The routine works fine if I put another completely separate object in the center of the map.

jwvanderbeck

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Having a problem with Find Closest
« Reply #2 on: December 11, 2014, 12:32:04 AM »
I think I have solved this.  It appears as though I have to uncheck the "visible to camera" option.  I don't know why, because the spawned stars are all visible to the camera.  But for some reason it appears to be working if I disable that option.

jwvanderbeck

  • Playmaker Newbie
  • *
  • Posts: 18
Re: [SOLVED] Having a problem with Find Closest
« Reply #3 on: December 11, 2014, 02:25:00 PM »
This was marked as solved, and while I hve got it working, I still question whether this is working as intended.

Is there some quirk of the Create Object that I am not aware of that would make these objects be invisible at the time Find Closest is run?  I don't understand why turning off the Visible filter works when these are all visible objects.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: [SOLVED] Having a problem with Find Closest
« Reply #4 on: December 11, 2014, 02:44:53 PM »
The template doesn't seem to work on my end. What version of Unity/PM are you using?

Find Closest will consider all of the GameObjects in the scene and store the one that is closest to the GameObject you have specified in that first Game Object (Use Owner by default) field. If you specify a tag, only objects on that tag are considered. Ignore owner will ignore the object in the first Game Object (Use Owner by default) field.

Store Object is the absolute closest object by distance of all of the considered objects. Store Distance will give you the literal distance between that nearest gameobject that was found and the origin game object.

Must Be Visible is a little bit deceptive in the editor, as the Scene View counts as a camera contributing to visibility.

This is an expensive operation by nature so be careful with using it everyFrame on multiple objects.

Hope that clarifies what the action is for.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jwvanderbeck

  • Playmaker Newbie
  • *
  • Posts: 18
Re: [SOLVED] Having a problem with Find Closest
« Reply #5 on: December 11, 2014, 03:02:32 PM »
I am using the latest version of both to the best of my knowledge.

My confusion lies in the "Visible" flag.  According to the docs, this flag means "Only consider objects visible to the camera."

However if I have it set to TRUE, then my routine will not work, because Find Closest will ignore all my stars, even though they are clearly visible to the camera because I can see them in the game view.  If I set this to FALSE then the routine considers the Stars as I need, and everything works.  Why I need to set it to FALSE when the stars are visible to the camera is what is confusing me.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: [SOLVED] Having a problem with Find Closest
« Reply #6 on: December 11, 2014, 03:13:59 PM »
Do you have multiple cameras, or any addons that affect your camera(s)? It's possible that something is interfering.

Doing this on the first frame of the game before everything has time to be initialized could also be an issue. Try using Next Frame Event or even waiting a second before running the action and see if that helps.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jwvanderbeck

  • Playmaker Newbie
  • *
  • Posts: 18
Re: [SOLVED] Having a problem with Find Closest
« Reply #7 on: December 11, 2014, 03:48:51 PM »
Do you have multiple cameras, or any addons that affect your camera(s)? It's possible that something is interfering.

Doing this on the first frame of the game before everything has time to be initialized could also be an issue. Try using Next Frame Event or even waiting a second before running the action and see if that helps.

Only the one camera at the moment, and the spawn happens in response to a keypress at the moment, so it isn't first frame.  In fact i'm using the keypress at the moment exactly because doing it straight out was causing weird issues.  That said let me experiment with the timing as you say.