playMaker

Author Topic: How do you assign variables to prefab parts?  (Read 2128 times)

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
How do you assign variables to prefab parts?
« on: March 30, 2015, 07:06:15 PM »
So I have a tank that has several parts.  These parts are assigned to variables as game objects.  I currently have the tank in the hierarchy in the scene.  I manually assign the parts to variables.  I would like to put the tank as a prefab.  Then instantiate it, assign its parts to variables and reference its parts by variables.  How do I do this?

Some of these need to be game objects while others do not.

The picture shows the PS1-Tank-Main with its smaller children. 
     1) I need to set game objects on the parent, the body, the spawn point and other children.  (GO-P1-Tank)
     2) I need to set variables for its controls (P1-Tank-Speed-Left).

I am assuming the non-game object variables I can just set any time.  So for the tank speed, firing rate, reverse and so forth.  However, how about the GAME OBJECTS?  How do I set variables pointing at the parent and children of stuff I instantiate?

These need to be global variables to be accessed from other FSMs.

Thanks
« Last Edit: March 30, 2015, 07:10:45 PM by wheretheidivides »

jayhfd

  • Junior Playmaker
  • **
  • Posts: 71
Re: How do you assign variables to prefab parts?
« Reply #1 on: March 31, 2015, 01:10:16 AM »
Check out stuff like "get owner" to get the game object itself, and also find parent, get child num, find child, etc. You'll probably use 'set parent' too.

If you create a tank gameobject then save that game object as a variable, you can then create the other tank parts and set them as children of that game object, with the spawn positions being the turret/tracks/etc positions.

Haven't done much of this myself but pretty sure that's the gist of it.

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: How do you assign variables to prefab parts?
« Reply #2 on: March 31, 2015, 01:26:12 AM »
Thanks.  I sort of figured that.  I just don't know how.  Once you instantiate the tank, how do you assign the child object to variables?  You can't do it as a prefab, so I'm guessing a FSM on each object at the start to assign itself.  It's probably something easy and I'm sure jean and those guys have answered this 100 times.

jayhfd

  • Junior Playmaker
  • **
  • Posts: 71
Re: How do you assign variables to prefab parts?
« Reply #3 on: March 31, 2015, 01:45:52 AM »
I'm not 100% sure how you wanna 'assign the child object'.

You create/instantiate the tank, do the same for each part, save each part to a game object var (Create Object > Store Obj) then Set Parent to the saved tank var.