playMaker

Author Topic: Issue with using "Find GameObject" in the scene from a Prefab  (Read 1353 times)

Baesick

  • Playmaker Newbie
  • *
  • Posts: 4
Issue with using "Find GameObject" in the scene from a Prefab
« on: November 13, 2019, 11:48:50 PM »
Hi! How would you "find" an object in a scene from a prefab without getting a null reference? My prefab is instantiated in a pool using Pool Manager and everytime the prefab gets enabled, the search in "finding" the gameobject I want just led me to a NullReferenceException error. I tried debugging this error and I concluded that this error was produced by the "Find" action unsuccessful search of the gameobjects in the scene and not with my parameters.

P.S: I'm using the action "Find Closest" to search for a gameobject in the scene.I tried looking for a solution in the forum similar to this one but I didn't find the answer.

Can someone send me a fix for this?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Issue with using "Find GameObject" in the scene from a Prefab
« Reply #1 on: November 14, 2019, 01:31:35 AM »
Hi,

 Are you filtering by tag? if you do, then it's likely that there isn't such gameobject with that particular tag on the scene at the time of search.

what do you mean by "unsuccessful search of the gameobjects in the scene and not with my parameters." ? The action tries to find a object given the parameter you passed on that action.

Can you make some screenshot at runtime of the action and the scene browser showing the object it should have found?

Bye,

 Jean

Baesick

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Issue with using "Find GameObject" in the scene from a Prefab
« Reply #2 on: November 14, 2019, 02:47:52 AM »
Sorry for the late reply! ;) Here it is!

1.) Capture1 shows how the FSM named "Interaction" is in Edit Mode. This FSM was originally attached to a "prefab". The object I want the FSM to search for is the "Audio Manager".

2.) Capture2 shows the "Audio Manager" gameobject. It's tag matches the "Untagged" tag of the "Find Closest" action in the photo "Capture1".

3.) Capture3 shows the game at runtime. "Audio Manager" was gone.

Why did she have to leave meeee? :'(
« Last Edit: November 14, 2019, 02:55:00 AM by Baesick »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Issue with using "Find GameObject" in the scene from a Prefab
« Reply #3 on: November 14, 2019, 03:17:00 AM »
Hi,

 a prefab can not reference a scene object, so in your third screenshot, that's why the gameobject ref disappeared, a prefab can only reference itself and its children, that's all, when instantiated, you will have to reference gameobjects one way or the other from outside, or using findGameObject.

 - I don't think you need to use Findclosest here, you are not interested in distance between gameobject, but only to get the audiolistener, so simply use FindGameObject with a tag "audiolistener" and add this tag to your audiolistener, then it will work.

Bye,

 Jean