playMaker

Author Topic: Making Prefabs Children of certain GameObjects? [SOLVED]  (Read 8135 times)

Mayhem

  • Full Member
  • ***
  • Posts: 171
Making Prefabs Children of certain GameObjects? [SOLVED]
« on: March 09, 2013, 07:56:08 AM »
Hey there.

I have some certain prefabs. For Example Items which the Player can collect. If he/she does so, then the Item will disappear in the Scene. There's no problem.

But, as soon he takes the Item, the Inventory shall get this Item, too, as a little Icon. This Icon is a prefab. Now, when i use the "Create Object"-Action it creates the object, obviously, but NOT as child of the Inventory-Menu. How can i accomplish that via FSM?

I already tried the "Set Parent"-Function, but i only get this error:

Code: [Select]
InvalidOperationException: Operation is not valid due to the current state of the object
« Last Edit: March 11, 2013, 12:47:07 AM by Alex Chouls »

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: Making Prefabs Children of certain GameObjects?
« Reply #1 on: March 09, 2013, 08:03:20 AM »
create object has an output called "Store Object". Use that in the setParent action.
You cannot work with prefabs unless you try to manipulate their attributes. So you need to work with the newly created gameObject :)

Did that fix it?
Best,
Sven

Mayhem

  • Full Member
  • ***
  • Posts: 171
Re: Making Prefabs Children of certain GameObjects?
« Reply #2 on: March 09, 2013, 08:10:40 AM »
Aye, i just figured it out myself, i don't know if it is a better idea, so what do you think:

First State
I create the Object (Action) -> then i find the Object by its Tag and Store it in the GameObject-Variable i created

Second State
Setting the Parent by the GameObject-Variable.

That did the job!


Now i just have to figure out how i can access the Components of the Prefab-Object :D

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: Making Prefabs Children of certain GameObjects?
« Reply #3 on: March 09, 2013, 08:29:16 AM »
Your idea is solid, but have a closer look at you "create Object" action, if it looks like the one in the attachments then there's no need for an elaborate setup.

as for the components:
1) create an object variable
2) define the type of the object variable to whatever component you want to get (you can define it in the variable window after creating the variable and selecting it)
3) use a "get component" action with your new defined object variable. This will get the first component of that type on your gameObject. To get or set specific properties use "get property" or "set property" .

Best,
Sven

Mayhem

  • Full Member
  • ***
  • Posts: 171
Re: Making Prefabs Children of certain GameObjects?
« Reply #4 on: March 09, 2013, 08:47:28 AM »
Yep, it's the same Action, worked fine without "Find by Tag".

But now i got another question:

My UI Item has this UI-Sprite-Component:


And as you see, there is a Button called "Make Pixel Perfect".

But in the Properties, i couldn't find that option:



Is there a way to get to that nGUI-Make-Pixelperfect-Method via FSM?

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: Making Prefabs Children of certain GameObjects?
« Reply #5 on: March 09, 2013, 09:05:43 AM »
Nope, there is no attribute linked directly to pixelperfect. Instead the button works similarly to those in playmaker : It sends an event. This event takes screen size, texture size and calculates the pixel perfect size from them. That size is then applied to the gameObject.

For these kind of things you need to a bit more fancy. First you need to find out what the button actually "sends" , which is in programmer language, which function it invokes . For these kind of things there's the API. Almost each plugin has it's own API and nGUI's is here:
http://www.tasharen.com/ngui/docs/

There you start of by searching for your component (UIsprite). The first result should get you to the right thing. Now you see all the functions and properties this script/component has. The one we need is obviously MakePixelPerfect (); .

Now, to invoke this method we need to use the telltale action "Invoke Method".
https://hutonggames.fogbugz.com/default.asp?W56


And there you go, you should be able to make stuff pixelperfect now :)
Best,
Sven

Mayhem

  • Full Member
  • ***
  • Posts: 171
Re: Making Prefabs Children of certain GameObjects?
« Reply #6 on: March 09, 2013, 09:18:39 AM »
Dude, you're my personal hero. I just needed the "Invoke Method"-Action, i already looked up the API and thought: "Gosh, how can i access this Method via PM!" :D
It wolked like a charm. I think i start to learn all the PM-Actions by heart :D