playMaker

Author Topic: Easy & quick answer? Find Game Object action  (Read 2467 times)

eccoecco

  • Playmaker Newbie
  • *
  • Posts: 19
Easy & quick answer? Find Game Object action
« on: December 12, 2017, 09:24:05 PM »
I'm following along with the tutorial on Unity's website:
https://unity3d.com/learn/tutorials/topics/asset-store/playmaker-basics-and-invisibility?playlist=17132 ( even though I don't have the necessary assets as the link is dead )

What looks like it should be very easy; using a Find Game Object action to locate a prefab ( I assume ) in the project folder (4:55 in the video ) and assigning it to a variable but when I run in play mode the variable doesn't locate the game object and remains blank ( as is visible with the dubug mode on ). 

I'm sure this is a simple issue but I've just lost two hours trying to figure it out.

Any suggestions would be appreciated.
« Last Edit: December 12, 2017, 10:55:19 PM by eccoecco »

omgitstri

  • Playmaker Newbie
  • *
  • Posts: 46
    • My Prototypes
Re: Easy & quick answer? Find Game Object action
« Reply #1 on: December 12, 2017, 09:38:09 PM »
I'm following along with the tutorial on Unity's website:
https://unity3d.com/learn/tutorials/topics/asset-store/playmaker-basics-and-invisibility?playlist=17132 ( even though I don't have the necessary assets as the link is dead )

What looks like it should be very easy; using a Find Game Object action to location a prefab in the project folder (4:55 in the video ) and assign it to a variable, when I run play mode the variable refuses to locate the game object.  I've tried multiple types of assets.  It briefly worked with a basic cylinder that was in the hierarchy but just once and not since.

I'm sure this is a simple issue but I've just lost two hours trying to figure it out.  Please help!

Hello eccoecco,

I'm pretty sure the Find Game Object only works with objects in the scene. What's happening in the tutorial you've linked is that they probably instantiated that weapon into the scene when they start the game, that's why he uses the Find Game Object action to find it.

I haven't messed with this too much but if you want to get a prefab from a project, you could use the Resources Load action. You need to make sure the prefab you want is inside a Resources folder.

Hope this helps.
Tri Nguyen
Game Designer at Nvizzio Creations

eccoecco

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Easy & quick answer? Find Game Object action
« Reply #2 on: December 12, 2017, 10:58:15 PM »
Wouldn't that mean that the items would still be present in the hierarchy whether present beforehand or immediately on play ( after being instantiated)?  Because I've tried using the Find Game Object action for named assets or and prefabs both in and out of the Hierarchy and it's still not working.

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Easy & quick answer? Find Game Object action
« Reply #3 on: December 13, 2017, 02:01:24 AM »
Find game object works on prefabs in scene, but you should really avoid using it. It's better to save the object as a variable then pass it around FSM's.
Available for Playmaker work

eccoecco

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Easy & quick answer? Find Game Object action
« Reply #4 on: December 13, 2017, 12:40:47 PM »
That's kind of my problem; the Find Game Object is supposed to be locating a prefab in the scene but it's not.  As for assigning it to a variable, I thought that's what Find Game Object specifically ( and only ) does.

Even when I specifically assign a game object to a variable, in this case; WeaponMe, it "erases" the value when I hit play reverting to "Value: None ( Game Object)"
« Last Edit: December 13, 2017, 12:46:19 PM by eccoecco »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Easy & quick answer? Find Game Object action
« Reply #5 on: December 13, 2017, 12:44:48 PM »
Hi,
you should store the Game Object prefab when you create the object,
then you can use that variable to communicate.
There are some more possibilities,
I just recently made this video, maybe this can help :


eccoecco

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Easy & quick answer? Find Game Object action
« Reply #6 on: December 13, 2017, 12:48:04 PM »
Thank you for posting the video, I'm watching it now and I've just subscribed to your Youtube channel.
I'll try finding and assigning prefabs to variables based on your video later today or tomorrow but I don't think anything will change as the variables are reset on Play.
« Last Edit: December 13, 2017, 01:02:55 PM by eccoecco »

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Easy & quick answer? Find Game Object action
« Reply #7 on: December 14, 2017, 06:00:30 AM »
You're doing it wrong, prefab is one thing, instantiated prefab is another.

You need to save the object as variable on runtime. So, use get owner on the object you want to find and save it as gameobject variable, then use find object to find it. Bear in mind that you will have to save it as a global variable if you want to find it that way which is a no-no, or search by string which is inefficient.

I recommend saving objects and other data to arraylist or hashtables, then save the arraylist or hashtable proxy as a global variable so you can extract all objects and data from there.
Available for Playmaker work

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Easy & quick answer? Find Game Object action
« Reply #8 on: December 14, 2017, 09:33:56 AM »
Hi.
On the Find Game Object, be sure the name is spelled right and if the correct tag is selected

Also be sure the object you want to find is created 'Before' the find action is called.

eccoecco

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Easy & quick answer? Find Game Object action
« Reply #9 on: December 14, 2017, 03:16:18 PM »
You're doing it wrong, prefab is one thing, instantiated prefab is another.

You need to save the object as variable on runtime. So, use get owner on the object you want to find and save it as gameobject variable, then use find object to find it. Bear in mind that you will have to save it as a global variable if you want to find it that way which is a no-no, or search by string which is inefficient.

I recommend saving objects and other data to arraylist or hashtables, then save the arraylist or hashtable proxy as a global variable so you can extract all objects and data from there.

W