playMaker

Author Topic: Paste Component?  (Read 3882 times)

Alessandro.Previti

  • Playmaker Newbie
  • *
  • Posts: 4
Paste Component?
« on: June 30, 2015, 02:09:14 PM »
Hello, I'm afraid I'm lost because of a pretty banal issue.
I've object 1 and 2 saved as game object variables.
I've a Start -> Has Component, if yes -> Destroy Component of object 1 -> Get Component of object 2 and save it as global var "my component"-> ...
then I'd like to paste the component but I can't find such node.

I tried "Add Component", it allows me to specify the game object to add the component to, the type of component I wish to add, but not the source... I don't even see the option to feed it my var.

Can anyone help me? Thank you very much.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Paste Component?
« Reply #1 on: June 30, 2015, 03:43:10 PM »
Hi,

 You can't do that actually, not at runtime at least.

you will have to save each properties you can want paste from the source component and manually set all them properties on your target component.

What is the component you want to copy paste at runtime?

Bye,

 Jean

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Paste Component?
« Reply #2 on: June 30, 2015, 04:46:04 PM »
what you can do maybe is to activate/deactivate the components instead of destroying

Alessandro.Previti

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Paste Component?
« Reply #3 on: June 30, 2015, 04:54:05 PM »
Hi Jean, thank you for your answer.
Why is it not possible at runtime?
I use adventuremaker, by design it allows to use only one main camera, other cameras in the scene are used as placeholders: when triggered a set event, the main camera copies angle and coords from a specified camera.
Nor components (depth of field, for example) nor components values are copied.

In my specific case, I've an component to customize the frustum of the camera, what I want to do is:
having a main camera with the frustum component set to default,having placeholder cameras in the scene with custom frustum settings, to copy the custom frustum component values from a triggered camera and replace the main camera frustum component values; the operation should be repeatable every time a new camera is selected.

I thought that'd be as easy as removing the component from main, copy it from the secondary camera and paste it to the main again.

What would be the correct approach?
Thank you.

Alessandro.Previti

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Paste Component?
« Reply #4 on: July 02, 2015, 03:02:58 AM »
Bump!
Anybody can help me to understand how can I copy and paste all component values of a component at runtime, or a component itself?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Paste Component?
« Reply #5 on: July 02, 2015, 07:39:26 AM »
Hi,

 It's possible if you write a script to do so, but as is PlayMaker doesn't provide this.

There isn't any built in feature in Unity to copy/paste component at runtime, it has to be manually scripted somehow, and falls amongst the very complex type of scripts, especially if you expect the feature to copy paste ANY component, which is virtually impossible, because advanced components will have their own way of serializing, and currently, I don't think Unity has reached a unified serialization system ( or if it has, again, this is VERY VERY complex to achieve).

have you studied WhydoIDoIt system?

https://www.assetstore.unity3d.com/en/#!/content/3675

If there is somene that can give you an educated answer or actually build a system for you, it's this guy! So I would contact him personally and ask that question.

Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Paste Component?
« Reply #6 on: July 02, 2015, 07:41:33 AM »
Hi,

 also, if you are on Unity 5, there is a fork:

https://github.com/TheSniperFan/unityserializer-ng

Bye,

 Jean

Alessandro.Previti

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Paste Component?
« Reply #7 on: July 03, 2015, 02:12:14 PM »
Oh, thank you, that was an exhaustive answer.
I am surprised it's possible to get a component but not to paste it or its values, this comes because I'm poor at programming.
Thank you for having the patience to explain this.

I found a solution that I'll be testing, I get the component "get component" from one object, I save each property as variables "get Properties", I set the properties of the component of the second object using the variables "set properties".

I suppose this should work :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Paste Component?
« Reply #8 on: July 12, 2015, 01:26:38 PM »
Hi,

 I find this very odd too that you can't copy paste at runtime...

 Please keep us updated with your findings.

Bye,

 Jean