playMaker

Author Topic: Can't Access Properties Of A Global GameObject  (Read 5814 times)

grimmy

  • Junior Playmaker
  • **
  • Posts: 70
Can't Access Properties Of A Global GameObject
« on: April 09, 2014, 07:57:22 AM »
Because  prefabs can't have direct links to in game objects I need to set them up to reference previously 'found' GameObjects which are then stored in global variables.

Now I need to access the variables on these objects but I can't. How do I do this?

Basically, my prefab need to be able to access another objects variables each time it is instanced.

??


Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Can't Access Properties Of A Global GameObject
« Reply #1 on: April 09, 2014, 08:13:28 AM »
If the gameobject changes then you need to get the variables again unless you've hardcoded the names in, then you can just update the gameobject variable.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

grimmy

  • Junior Playmaker
  • **
  • Posts: 70
Re: Can't Access Properties Of A Global GameObject
« Reply #2 on: April 09, 2014, 08:43:47 AM »
Not sure how to get them again. 'Get property' wont work from prefabs because I cant't reference a global object from that action.
?


grimmy

  • Junior Playmaker
  • **
  • Posts: 70
Re: Can't Access Properties Of A Global GameObject
« Reply #3 on: April 09, 2014, 08:51:43 AM »
Eg I here I find the gameObject again> store it as a variable> but then there is no way to access the properties of that stored object.. see pic...

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Can't Access Properties Of A Global GameObject
« Reply #4 on: April 09, 2014, 08:59:44 AM »
Well prefabs in the Project Hierarchy can't connect to the Scene Objects so you have to spawn them in the scene before they can interact with stuff in the scene.

What are you trying to make happen here? Spawn a prefab and get some information at runtime?

Get Property requires an Object variable. Check out this tutorial.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

grimmy

  • Junior Playmaker
  • **
  • Posts: 70
Re: Can't Access Properties Of A Global GameObject
« Reply #5 on: April 09, 2014, 09:07:01 AM »
I understand that prefabs cant connect directly to scene objects, and that's precisely the issue I am trying to solve.

Basically, I want my prefab to connect to a gameObject (GlobalFunctions) and retrieve a variable from it. (This gameobject has a script attached)

Both the prefab and GameObject (GlobalFunctions)  I am trying to connect to exist at game start.

I have a global variable object in playmaker that IS the main  (GlobalFunctions) object, but how can I get properties from it? This object  (GlobalFunctions)  has a script attached to it that has variables I need to access.

grimmy

  • Junior Playmaker
  • **
  • Posts: 70
Re: Can't Access Properties Of A Global GameObject
« Reply #6 on: April 09, 2014, 09:22:31 AM »
I just tried using 'Get Component' and the 'Get Property' on the component. But the properties of my script don't appear..just the 'name' value!?? See pic...

Do I need a different Object Type? It's just a monobehaviour I want to access.

grimmy

  • Junior Playmaker
  • **
  • Posts: 70
Re: Can't Access Properties Of A Global GameObject
« Reply #7 on: April 09, 2014, 09:33:00 AM »
Okay, I think I got it. I used the process above (Get component>Get Property) but I made sure that the variable that stored them in it the correct type. In my case None (GlobalFunctions) see pic...

grimmy

  • Junior Playmaker
  • **
  • Posts: 70
Re: Can't Access Properties Of A Global GameObject
« Reply #8 on: April 09, 2014, 09:43:11 AM »
I cant mark this as solved though because my method meant that I actually needed to get the object and store it again locally rather than using properties from a global object...which is still impossible as far as I can tell.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Can't Access Properties Of A Global GameObject
« Reply #9 on: April 09, 2014, 09:55:24 AM »
I cant mark this as solved though because my method meant that I actually needed to get the object and store it again locally rather than using properties from a global object...which is still impossible as far as I can tell.

I'm not following whats going on here. What are you trying to do at a high level?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

grimmy

  • Junior Playmaker
  • **
  • Posts: 70
Re: Can't Access Properties Of A Global GameObject
« Reply #10 on: April 09, 2014, 11:06:32 AM »
..Make a prefab get a variable from a script attached to an object.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Can't Access Properties Of A Global GameObject
« Reply #11 on: April 09, 2014, 11:24:53 AM »
So you need to get 1)The object.. 2)The script.. 3)The variable(s).

The Get Component, Get Property flow is the way to do that unless you code up a new custom action to do something more specific.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

grimmy

  • Junior Playmaker
  • **
  • Posts: 70
Re: Can't Access Properties Of A Global GameObject
« Reply #12 on: April 09, 2014, 11:59:03 AM »
Yes but the problem is that I can't get the object..or at least I can't build this process into the prefab itself...which is what I want.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Can't Access Properties Of A Global GameObject
« Reply #13 on: April 09, 2014, 12:46:55 PM »
I'm don't really see how you wouldn't be able to do either of those. Am I missing something?

For getting the GameObject if its in the scene then you could just store it as a global, then link that up in the prefab. If not, then you could find it at runtime when the prefab spawns.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

grimmy

  • Junior Playmaker
  • **
  • Posts: 70
Re: Can't Access Properties Of A Global GameObject
« Reply #14 on: April 09, 2014, 12:56:38 PM »
I am really confused and playmaker is making me bang my head against the wall. It's been 3 days into my first full production using it and things are a complete mess. I've been trying to keep everything as neat and possible.(Hence the prefabs trying to find objects at runtime) ...but it's taking ages to get through the code... and what is worse, things seem to be slowing down the further I go....this is beyond frustrating!

1. I have stored my object in a global variable.

2. I cannot access the variables on this object at all. How can I do this??!

Cheers

Apologies if I seem on the verge of madness..I am..!