Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: japporeactor on December 08, 2021, 06:30:56 AM

Title: Find in scene the prefab instantiated by another script and use it in FSM
Post by: japporeactor on December 08, 2021, 06:30:56 AM
Hi,

I'm pretty noob to Playmaker, I'm trying to find a way to modify a parameter on a character (prefab) instantiated at start by another script (not playmaker based). Say I want that character to enter a trigger and modify it's health or so. I'd start putting the FSM on the trigger, but obviously using the prefab from the project window in the FSM won't work as it would modify the prefab and not the instantiated one. How would you go about finding an instantiated character in the scene and use that one in an FSM? Sorry for the noob question, I've tried searching about prefab with not much luck.


Title: Re: Find in scene the prefab instantiated by another script and use it in FSM
Post by: djaydino on December 08, 2021, 10:52:19 AM
Hi.
if the character is instantiated by the script, then add a fsm to it and also set a global variable :

on start game set a object that will not get destroyed and use 'Set Game Object' to set it to a Global Variable (call it 'Data Holder' for example).
Then set a fsm on it (call it 'Data' for example)
then add a variable and call it 'player' for example)

Then on the character prefab you can use "Set Fsm Game Object"
target the global (Data Holder) and the Data fsm and the variable name 'player'

Now you can use "Get Fsm Game Object" to reference the 'player' from any other fsm/object