playMaker

Author Topic: Get Property loses reference to Target Object [SOLVED]  (Read 8577 times)

ninjingames

  • Playmaker Newbie
  • *
  • Posts: 4
Get Property loses reference to Target Object [SOLVED]
« on: March 27, 2014, 06:55:08 AM »
I have an empty game object with a C# script component attached to it. The script has some public float variables which I want to access from PlayMaker via the Get Property action. This works as intended until I reload Unity, change build targets or re-load the scene, then the Get Property action just shows "None (Object)" as Target Object and no more Property and Store Float dropdowns and I have to redo the whole Get Property action.

Steps to reproduce:
I drag the script in the action list and select Get Property. I now have a Get Property action with the script as Target Object. I select the Float in want to use from the dropdown list for Property and store the float in a PlayMaker variable.
I test my program and everything works as intended. PlayMaker successfully reads the public float from that script and stores it in the specified variable.
I save everything, close Unity, restart Unity and now the Get Property action says Target Object "None (Object), Property is gone, Store Float is gone, but Every Frame box is still checked. Of course the program doesn't work anymore and I have to delete the Get Property Action and do the whole procedure again.
The same happens when I change my build target or open another scene and then re-open this scene.

Am I using Get Property wrong or is this a bug?

PlayMaker version 1.7.7.1
Unity version 4.3.4f1

EDIT: Problem solved! See my explanation here:
http://hutonggames.com/playmakerforum/index.php?topic=6821.msg33537#msg33537
« Last Edit: April 01, 2014, 12:08:52 PM by ninjingames »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Property loses reference to Target Object
« Reply #1 on: March 27, 2014, 07:38:47 AM »
Hi,

 it's likely that you are referencing an asset from the Project, you need to reference what's in the scene hierarchy.

bye,

 Jean

ninjingames

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Get Property loses reference to Target Object
« Reply #2 on: March 27, 2014, 08:33:04 AM »
I don't think that's the problem...

I click on the InputManager object in the Scene Hierarchy (it's an empty object with some scripts attached to do some initializing for virtual joysticks) and then drag the script from the Inspector onto the action list in PlayMaker. ObjectType is stated as InputManager in the Get Property action and I can select the public variables of the script in the Property dropdown. Everything works as intended (until re-load).

If I drag the script from my assets folder as you are suggesting, it says ObjectType is UnityEditor.MonoScript and then I can't even select the public float variable in the Property dropdown (it only shows name, name.length, text and text.length).

ninjingames

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Get Property loses reference to Target Object
« Reply #3 on: March 28, 2014, 06:21:34 AM »
Hi,

 it's likely that you are referencing an asset from the Project, you need to reference what's in the scene hierarchy.

bye,

 Jean

I've made some more tests and everything I reference from my assets survives a reload. Everything I drag from my scene hierarchy is lost on reload.

Referencing a script from my asset folder is useless anyway as I can't access its public variables via get property. This leads me to another question. Why does the little Target icon next to Target Object offer me to select objects from my assets and not from my scene hierarchy? This was also asked in this thread, but never answered:
http://hutonggames.com/playmakerforum/index.php?topic=3561

I really need to be able to use the get property action properly for my project.  I'm close to abandoning using PlayMaker and just do it the old-fashioned way, but that's not what I've paid 95$ for...
Any help is much appreciated!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Property loses reference to Target Object
« Reply #4 on: March 28, 2014, 09:00:20 AM »
Hi,

 that's really odd indeed, I am using it all day long without a problem.

 could make a screencast of what you are doing? maybe Iw ill be able to spot where things go wrong in the process?

 also, if you can share the project, that will allow me to see if it's reproduceable.

bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Property loses reference to Target Object
« Reply #5 on: April 01, 2014, 07:39:18 AM »
Hi,

 ok, so the opposite is true, if you select a prefab, you can't reference gameobjects in the scene, that won't work neither, for this you'll need to wire referencing when the prefab is instanciated at runtime.

bye,

 Jean

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Get Property loses reference to Target Object
« Reply #6 on: April 01, 2014, 08:45:26 AM »
Unity can sometimes allow this to happen, then refactor and view it as an unacceptable connection.

Here is a recent video on how to get data from scripts, both between prefabs and scene objects. You want to utilize Get Component at runtime. (Apologies for the audio quality, I've since got a *much* better mic and improved the quality.)


I had what you're describing happen to me when i first started doing that sort of thing, and now I don't have an issue so I'm assuming its just a matter of proper execution here, if not then I think a screencast or something would really help clarify whats going on.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

ninjingames

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Get Property loses reference to Target Object
« Reply #7 on: April 01, 2014, 12:04:52 PM »
Thanks to Jean's help I could solve the problem.

I've kind of expected PlayMaker to automatically do the "Find Game Object" and "Get Component" actions in the background when I drop a component onto a "Get Property" action in a prefab object. Seems like I still have to use my head and do some work of my own, even with PlayMaker  ;D

For those that have the same problem. When you have an FSM attached to an asset in the scene hierarchy and want to get a property from another asset in the scene hierarchy, simply drag the component onto the Target Object field of a "Get Property" action. The problem happens, if you have an FSM attached to a prefab and want to access a property of an asset in the scene hierarchy. To do this you have to:

- Create two variables. One of the type GameObject, to store a reference to the game object you are trying to access in the scene hierarchy and one of the type Object to store a reference to the component that has the property you want to get. Important: For the variable of type Object you have to set the Object Type to the type of the component you want to access.
- Create a "Find Game Object" action and find the object you want to access via its name or tag. Store it in the variable of type GameObject created earlier.
- Create a "Get Component" action, select "Specify Game Object" and select the variable where we stored the game object from "Find Game Object", then store the result in the Object variable.
- Finally create the "Get property" action and use this Object variable as the Target Object.

Done!  8)