playMaker

Author Topic: how to access the rigidbody of a spawned prefab [SOLVED]  (Read 2713 times)

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
how to access the rigidbody of a spawned prefab [SOLVED]
« on: November 10, 2019, 05:55:30 AM »
what why can I access the component of a spawned prefab using playmaker?

Scenario:

I wish to spawn a grenade in the player's hand, but I need to turn on/off "is kinamatic".

while the grenade is in his hand "is kinamatic" is on. Then just before I add force I need to turn this property off.

I have tried, but it seems this is not possible.

But maybe I'm missing something simple?
« Last Edit: November 11, 2019, 11:38:54 AM by colpolstudios »

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: how to access the rigidbody of a spawned prefab
« Reply #1 on: November 10, 2019, 07:38:01 AM »

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: how to access the rigidbody of a spawned prefab
« Reply #2 on: November 10, 2019, 02:41:09 PM »
I seem to have run into another issue.

I need to set the parent of the grenade to the player and im not allowed :(

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: how to access the rigidbody of a spawned prefab
« Reply #3 on: November 11, 2019, 02:44:21 AM »
Hi,

 when you spawn a prefab, you should always save the instance in a variable, then you can do everything with it as you do with a regular gameobject ( because a spawned prefab is just a gameobject in the end)

Bye,

 Jean

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: how to access the rigidbody of a spawned prefab
« Reply #4 on: November 11, 2019, 03:32:30 AM »
You can try this one, but get it from Ecosystem:
https://hutonggames.com/playmakerforum/index.php?topic=19487.msg84942#msg84942

Thanks for the action, is it possible also to access a script that is on this prefab?

I need to be able to activate/deactivate this script.

The fsm on the spawned prefab is trying to do this, but atm I can't :(

Thanks, jean, im am still working through some issues and shall try your suggestion when im ready.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: how to access the rigidbody of a spawned prefab
« Reply #5 on: November 11, 2019, 05:00:21 AM »
Hi,

no, you can't and should not modify prefabs, you should only modify the instance you create with it.

 maintain some variables in the fsm that spawn this prefab so that when it spawns, it can deactivate or activate a certain component on it, or have the prefab instance responsible for that, where component would be disabled by default and enabled if necessary.

the fsm on the spawned prefab can enabled disable any component on itself or on any object it's given, by maybe the fsm itself is disabled, which then is logical that it can't do anything.

Bye,

 Jean

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: how to access the rigidbody of a spawned prefab
« Reply #6 on: November 11, 2019, 11:38:24 AM »
In the end, I got it to work but not using a prefab at all.

The grenade is now a child of the character and activated or deactivated.

It's like a pooled object, but though going to get it all working.

Middle mouse to activate grenade.

right mouse button to aim, using trajectory predictor.

Left mouse to apply force.

I've also been able to tie this into my custom aiming system, and the crosshair target now acts as the target location for the grenade landing point.

I don't have a web demo just yet as I need to define the new ability to the joystick.