playMaker

Author Topic: String Variable to Game Object.  (Read 4807 times)

mweyna

  • Full Member
  • ***
  • Posts: 242
String Variable to Game Object.
« on: February 08, 2014, 04:25:48 PM »
String to Game Object action. Set Name only appears to work if the object exists in the scene already.

I'm trying to set a String variable to a name of the Pre-fab obect (one not in the scene yet), but can't find a reliable way to do the conversion.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: String Variable to Game Object.
« Reply #1 on: February 10, 2014, 02:54:16 AM »
Hi,

 I am confused. "Set Name" only set the name of a gameobject you already have a reference to.

Use "find GameObject" or "Find Child" to search the scene for a gameobject of a specific name.

Bye,

 Jean

mweyna

  • Full Member
  • ***
  • Posts: 242
Re: String Variable to Game Object.
« Reply #2 on: February 10, 2014, 01:39:37 PM »
So I managed to create a workout with a bunch of new things, but findGameObject or FindChild as you said only works for scene objects. I was trying to find a prefab object with a particular string name.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: String Variable to Game Object.
« Reply #3 on: February 10, 2014, 02:22:56 PM »
Since prefabs are static during runtime you can define them explicitly, there is no need to search for one.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: String Variable to Game Object.
« Reply #4 on: February 11, 2014, 06:42:33 AM »
Hi,

 or you can use this action which loads a prefab from the "Resources" by its name:

http://hutonggames.com/playmakerforum/index.php?topic=3916.msg18214#msg18214

Warning, "Resources" is a special thing to learn from first:
https://docs.unity3d.com/Documentation/ScriptReference/Resources.html

bye,

 Jean

mweyna

  • Full Member
  • ***
  • Posts: 242
Re: String Variable to Game Object.
« Reply #5 on: February 12, 2014, 01:13:18 AM »
So I found a workaround which solves it (although probably not the most effective way). Each Prefab I create has a preset String variable called prefab.name.string. When I create the object, I add that name to a fairly often updated Array, along with other stats of that item. When I then load it, I get the original object name (since all the files are in seperate folders based on the item name, not prefab name), then load that prefab.name.string to spawn using my PoolManager. Then just load all the specific attributes to it. It's a pretty heavy FSM, but gets the job done.