playMaker

Author Topic: Accessing components inside instanced prefabs?[SOLVED]  (Read 6081 times)

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Accessing components inside instanced prefabs?[SOLVED]
« on: October 30, 2013, 04:03:14 PM »
Recently I've been wondering about something and if there is a better way to go about doing this...

Normally for editing components we would use Get/Set Property and just drag them in and modify them from there since its super awesome and great and everything.

This doesn't apply for prefabs, if its a spawned prefab during runtime then how can I access its components from an FSM in the scene? I can setup an FSM in the prefab to wait for data and fire an event after the scene FSM sends it data, but this isn't as flexible.

I don't know how Get Component works, it seems to be aimed at filling this need but I don't see where to define the object type or how to manipulate the component after getting it. Plus, what if there are multiple components I need to edit on the target gameobject?

I'm trying to avoid making actions for every unsupported property of a component that I need to change realtime on instanced prefabs if possible.
« Last Edit: November 01, 2013, 09:28:20 AM by jeanfabre »
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: Accessing components inside instanced prefabs?
« Reply #1 on: October 31, 2013, 03:43:39 AM »
Hi,

 Prefab reference works within the prefab hierarchy itself, so you can reference a child of a prefab, and that reference will be properly carried over as you instanciate this prefab.

 Now, a prefab willing to reference another object in the scene must be set at runtime.
 either by searching for that object, or by listening to a event fired by thatobject and store the reference of the sender.

 also, you can store objects in a global fsmGameObject, and that becomes then accessible by anything.

bye,

 Jean

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Accessing components inside instanced prefabs?
« Reply #2 on: October 31, 2013, 06:42:29 AM »
Right, but what about components? How would one grab some variable on a component inside prefab that was created during runtime?

For instance if I spawned a particle system and wanted to use some existing object in the scene to get the color variable and animate it after it spawned. Is it possible to do so without making a custom action for that particular variable on the component?
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: Accessing components inside instanced prefabs?
« Reply #3 on: October 31, 2013, 07:17:54 AM »
Hi,

 I need a concrete example cause I am not we are visualizing the same set up.

Components are very much like gameobject in terms of referencing, so you will have to save references of component into a FsmObject of the type of your component. I guess this is your question.

bye,

 Jean

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Accessing components inside instanced prefabs?
« Reply #4 on: October 31, 2013, 07:30:22 AM »
Here's where I'm at.

For example, realtime create some particle system (prefab gameObject) and animate the color (or any particular variable in the component) from a gameObject Fsm in the scene.

So far I've hit a wall after I get the component and don't know where to go from there.
« Last Edit: October 31, 2013, 07:38:36 AM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Accessing components inside instanced prefabs?
« Reply #5 on: November 01, 2013, 05:19:04 AM »
I am just going to throw this out as a quick random idea. we already know that when we spawn a pre fab into the game it becomes "PreFab(clone)". the fact that Unity tacks that on their makes using the prefab gameobject drag and drop useless.
Now once your pre fab is in your asset folder you can edit it with Playmaker like any object in the scene and it will auto update (no need to apply changes.)
You can also pick any object in your scene, lock it in the playmaker editor and then select your pre fab in your asset folder and drag the components into the FSM editor to use get and set.
Now my idea is that you set your pre fab up to instantly reset it's name and lose the (clone) and then what ever object is looking for it might be able to find it. You might have to set up a Fsm that will loop until it finds the pre fab game object. I have done this using "gameobject is null".

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Accessing components inside instanced prefabs?
« Reply #6 on: November 01, 2013, 07:12:55 AM »
Hi,

 I think you are over thinking this.

 in your Main Camera fsm, state 2, add a "set property" and reference "SomeComponent" in the Target Object, and done, you can access the Partical System public property, just like when you drag that parcticle component on the state action stack.

 Am I looking at the right issue here?

bye,

 Jean

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Accessing components inside instanced prefabs?
« Reply #7 on: November 01, 2013, 09:18:36 AM »
Aw man, can't believe I missed that. I never connected the dots after I tinkered with Get Component that I could fill Set Property with its results since I'm so used to having to drag'n'drop components into Set Property and have it identify what component type I put there.

Derp derp.

Thanks
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D