playMaker

Author Topic: How to attach something to a GameObject at runtime?  (Read 4128 times)

DeepShader

  • Playmaker Newbie
  • *
  • Posts: 33
How to attach something to a GameObject at runtime?
« on: May 12, 2015, 01:33:10 AM »
Hello,
how can I attach something to an GameObject at runtime with PlayMaker?

I want to create GameObjects at runtime (that's not the problem) and I want to attach PlayMaker Controls to these new GameObjects at runtime with PlayMaker.

Is this possible?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to attach something to a GameObject at runtime?
« Reply #1 on: May 12, 2015, 02:46:14 AM »
Hi,

 What do you mean by "Playmaker control".

there are two distinct concept in Unity:

--  attaching Gameobject together, forming a hierarchy. you can achieve this using "set parent"

-- attaching component/behavior to a GameObject, you can achieve this using "Add Component" action, but I don't rely recommend you do this.

typically, if you want to switch on and off an "fsm" logic, you can deactivate the Fsm using "EnableBehavior" or implement the swith in your fsm logic by sending events for example.

if that is still not clear, can you further explain what you are after?

 Bye,

 Jean

DeepShader

  • Playmaker Newbie
  • *
  • Posts: 33
Re: How to attach something to a GameObject at runtime?
« Reply #2 on: May 12, 2015, 02:53:51 AM »
If I create an image-instance for my UI at runtime (via Playmaker) I want to add a Playmaker-touch-control to this instance/GameObject.

Or is it possible to add this attachment to the "original" of the instance and it will be attached to the instance automatically?

If yes, how can I address this FSM (instance) later?

Background:

The user should be able to delete this image-instances later by clicking on a button in the UI.

First I just wanted to add a button and a raycast should look which image is selected, but this don't seems to work. So my new idea is to make the image touch-able and if the user touches an image a menu should appears (with delete, etc).

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to attach something to a GameObject at runtime?
« Reply #3 on: May 12, 2015, 03:08:38 AM »
Hi,

 For this, you should use prefabs, you are doing this right?

 I assume you do, then all the logic is already there in your prefab, and instead of doing a raycast or manual operation, rely on the UI system to stay informed of where the use clicked, so your prefab will implement the UIS proxy to receive click event ( you have the UI package from the wiki right?)

then each image is actually responsible to handle it's interaction with the user.

 Please study the various UI samples on the ecosystem, especially the latest listing sample where you'll see how to create a list dynamically at runtime and handle communication, menus ( the delete button appears when hovering the item, etc)

https://twitter.com/JeanAtPlayMaker/status/595596254563958784

Bye,

 Jean

DeepShader

  • Playmaker Newbie
  • *
  • Posts: 33
Re: How to attach something to a GameObject at runtime?
« Reply #4 on: May 14, 2015, 03:19:56 AM »
Thank you, but this doesn't work with an UI image, which I need for my image-slider, where the user should select the image.

Is there another way to realized that? Should I try to use buttons with the image as graphic instead of an UI image to handle that?

DeepShader

  • Playmaker Newbie
  • *
  • Posts: 33
Re: How to attach something to a GameObject at runtime?
« Reply #5 on: May 14, 2015, 03:38:40 AM »
What I need is something like that - but in PlayMaker ^^

(on 3:57m)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to attach something to a GameObject at runtime?
« Reply #6 on: May 14, 2015, 05:11:00 AM »
Hi,

 use a UI Button, and set the image of the button to be the one you need.

Bye,

 Jean

DeepShader

  • Playmaker Newbie
  • *
  • Posts: 33
Re: How to attach something to a GameObject at runtime?
« Reply #7 on: May 14, 2015, 05:17:03 AM »
Ok, so EvenTrigger isn't possbile with PlayMaker o_O

Any plans for that soon or does all people who want to use Even Trigger have to switch to something like Blox?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to attach something to a GameObject at runtime?
« Reply #8 on: May 21, 2015, 06:59:37 AM »
Hi,

 use raw Pointer information, that works too.

The uGui package for PlayMaker has a pointer proxy, and that works for any UI elements. Have you studied the various ugui samples on the Ecosystem? the drag and drop sample is making use of this case.

Bye,

 Jean