playMaker

Author Topic: Set GameObject variable by name without using 'find'  (Read 1685 times)

lukew

  • Playmaker Newbie
  • *
  • Posts: 42
Set GameObject variable by name without using 'find'
« on: March 31, 2015, 11:04:32 AM »
Hey,

Is it possible to set GameObject variable without using 'find' if I know the exact name of that GameObject and there is only one GameObject with that name in the scene?

As far as I know Unity recommends to not use 'find' and 'find by tag' too much because of the performance. Maybe I should't care too much if I'm not doing this per frame and my target platform is desktop? Especially that I always use find by tag and there won't be more than XX-XXX objects with a same tag in the scene.

Why I need it? For example. I want to loot a corpse. Player is doing 'use' on the corpse. FSM knows that it should perform a looting sequence now. It knows the name of the corpse/npc and it needs to find the GameObject with a PlayMaker array list attached that stores the inventory of that corpse (It's stored in a different place, it's like a database structure. Inventories, npc stats etc. are stored in a separate location because they are always in the scene while the npcs are spawned in runtime at the start (not stored in the scene). Let's say that npc GameObject is called 'NPC_John' and it stores skinned mesh, animator, AI FSMs etc. and it's spawned in runtime while there is another GameObject called 'DB_NPCSTATS_John' which stores all stats, attributes, position, inventory, actual weapon, actual armor etc. and all other data (mostly via array lists and hash tables) that needs to be saved/loaded.

At this moment I know what's the name of a GameObject that has the array list attached but I need to use 'Find Game Object' action to set the Game Object variable before I can perform next array list actions on it.

I know that I can copy array lists from the 'database' GameObjects to the ncp GameObjects after loading a game state and spawningn them so I would avoid finding separate objects in this case. Anyway I think that setting GameObject variable just by name without using 'find' would be very useful. Is it possible?
« Last Edit: March 31, 2015, 12:11:02 PM by lukew »

lukew

  • Playmaker Newbie
  • *
  • Posts: 42
Re: Set GameObject variable by name without using 'find'
« Reply #1 on: April 02, 2015, 12:23:55 PM »
Bump.

Any input will be much appreciated. Thanks!