Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: SawyerK on December 01, 2024, 04:18:13 PM

Title: Unable to set Global GameObject value
Post by: SawyerK on December 01, 2024, 04:18:13 PM
Hi!

I'm unable to set Global GameObject value by dragging GO to the empty "value" space, it only allows me to select GO from assets.

I use "GetOwner" action to set the GO value but the problem with this is that if another action uses this Global GO in the "start" state then it throws an error.

It would be nice if I could set the Global GO value in the Global Variables tab so I can prevent this error, because right now the only option I have is to not use any action on the "start" state that references Global GameObjects which is not ideal for me.
Is there a workaround or fix for this?
(https://i.postimg.cc/DzLS96SC/global-GO1.jpg)
(https://i.postimg.cc/GhgTGH0j/global-GO2.jpg)
(https://i.postimg.cc/sgBQcssC/global-GO3.jpg)
(https://i.postimg.cc/Bnd87knL/global-GO4.jpg)
Title: Re: Unable to set Global GameObject value
Post by: jeanfabre on December 02, 2024, 04:03:04 AM
Hi,

 It's a common misunderstanding indeed: a scene can be loaded and unloaded during the life time of a game, and if you have a playmaker global variable, you can't reference a gameobject from a scene during editing time, because unity doesn't know if that scene is going to be always loaded.

I too think it's a big short coming, but it's not a PlayMaker issue, it's how Unity was designed. and Regular scripts have the same restriction.

There are two main ways to go about it:

- have a dedicated tag for this gameobject, and then an fsm can search in he loaded scene by tag and get it, store it the global variable. Do that once, don't have every fsm trying to find that gameobject by tag, indeed use a global variable and do it once or when needed udinrg initialision after the scene was loaded.

- have an fsm on that gameobject that set the global variable. Then it saves the trouble of keeping track of scene loading to search for it by tag or name.


be sure in all cases, to always check that the variable is not null, so if an fsm is using that global variable, it has to first check if it's null or not.

Bye,

Jean