playMaker

Author Topic: Add component extention.[SOLVED]  (Read 3728 times)

Sjones

  • Full Member
  • ***
  • Posts: 203
Add component extention.[SOLVED]
« on: January 30, 2013, 07:53:58 PM »
I have had a few issues with the rigidbody component not working correctly when spawning a prefab. to fix this I have had to add the rigidbody component at run time.

to do this I have been using the add component action to add the rigidbody after the prefab has been instanced in the level, my issue is that I then want to set the properties on the rigidbody component that was just created

using the set property will give me access to the rigidbody but will only reference the object that I drag into the property box from the scene. However I need to reference the owner and its newly created rigidbody instead

so my thoughts was possibly to extend the "add component" action to store its created component into an 'object' variable, to then pass on into the set property.

my problem is I cant work out how to do so so was wondering if anyone can give it a shot, I shouldnt imagine it would be that hard for someone who knows scripting however I have already spent a few hours on the issue and haven't been able to make any progress.

Edit*
Added an image to explain things a bit better, the create component result to the set property target object
« Last Edit: January 31, 2013, 12:27:55 AM by jeanfabre »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Add component extention.
« Reply #1 on: January 30, 2013, 08:20:21 PM »
You should be able to use Get Component to get the added component.

But I really like your suggestion of just storing it in Add Component.

I've attached an updated Add Component action. Let me know how it works for you...

Sjones

  • Full Member
  • ***
  • Posts: 203
Re: Add component extention.
« Reply #2 on: January 30, 2013, 08:21:51 PM »
oh wow, thanks for that!

wasn't expecting such a fast reply, testing it now will let you know how it goes.

Sjones

  • Full Member
  • ***
  • Posts: 203
Re: Add component extention.
« Reply #3 on: January 30, 2013, 08:42:04 PM »
just gave it a quick test however the script itself wont allow me to enter a "object" variable into the store component field, it doesn't seem to let me add any type of variable and just appears as "none" in the list

Edit*
so I havnt used the object variable before and not realising you have to specify the object type first, so changing it to type component worked (taking a quick look at the code helped)

however, once the add component worked, was able to put the same variable into set property where things didnt go as expected / had a feeling this may be an issue.

because the store component doesnt get the component type until the script is run in the level, when injecting it into set property it comes up with the list of components available instead of the "add components" "components type" properties.



« Last Edit: January 30, 2013, 09:07:33 PM by Sjones »

Sjones

  • Full Member
  • ***
  • Posts: 203
Re: Add component extention.
« Reply #4 on: January 30, 2013, 09:50:45 PM »
sorry for the multiple posts, so after testing your script I went on to try your suggestion of using get component and reading up on the object variable some more and that method works perfectly for this situation.

further more, it occurred to me that instead of setting the object type to component and setting it to rigidbody (or the same type as the add component type) might also work for the script you gave, and low and behold, it works!

so I would like to apologise for any inconvenience I may of caused and to thank you for your quick and helpful response to the original post :)