Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: PolyMad on October 04, 2018, 04:26:05 PM

Title: What am I doing wrong?
Post by: PolyMad on October 04, 2018, 04:26:05 PM
I have an object CANVAS in the scene.
It's in the root.
I find an object called exactly "CANVAS" in the scene and store it in a variable.
Then, I activate that object.

WHAT CAN GO WRONG IN THESE TWO DAMN ACTIONS?

Playmaker is great but so so so so often it's so counterintuitive and convoluted it just brings to rip your hair from your head.
Title: Re: What am I doing wrong?
Post by: DanielThomas on October 04, 2018, 04:37:09 PM
You're not saying what the problem is?
I would assume it doesn't activate the game object because the variable is empty when it tries. If this is the case, set it to "action sequence" to make sure it has found the game object and put it in the variable before trying to activate it.

https://hutonggames.fogbugz.com/default.asp?W1255
Title: Re: What am I doing wrong?
Post by: PolyMad on October 05, 2018, 12:44:45 AM
Oh god, I didn't know about this action sequence thing, I thought it was ALREADY working like that... thank you for the hint, I'll activate this EVERYWHERE.

However, activated action sequence, still not working... and I swear that the object in the scene is named "CANVAS" and the string in the action is "CANVAS".
How is it possible that it doesn't find it?
Title: Re: What am I doing wrong?
Post by: PolyMad on October 05, 2018, 01:59:46 AM
Maybe I found the problem... the CANVAS is DISABLED, and that's EXACTLY why I need to find it: to enable it!
And this action doesn't allow to include disabled objects!

The fun part about all this is that I disabled the canvas simply because I don't like to see it around while I am working on the scenery. Goddamnit!

Edit: maybe I found a workaround for this, even though I will have to manually add the CANVAS object to a FSM variable in each of my maps, which kind of defeats the "all automated" system I wanted to setup, but ok...

One curiosity: is it Unity that doesn't allow to find disabled GameObjects or this could be easily added to the Playmaker action?
Title: Re: What am I doing wrong?
Post by: jeanfabre on October 05, 2018, 02:11:38 AM
Hi,

yeah, it's important to understand what each action refers to and what Unity apis it uses. Find() ignores inactive objects

https://docs.unity3d.com/ScriptReference/GameObject.Find.html

you'll see it mentions that "This function only returns active GameObjects. "

 The other problem is that Finding object by name is slow in Unity, and so this is not recommended to begin with.

 What I would consider instead is  one of the following:

- maintaining a global variable, that an Fsm that knows about the canvas sets when it starts. You do that prior deactivating the canvas (https://hutonggames.com/playmakerforum/index.php?topic=1732.msg7589#msg7589)

- Have an Fsm on your canvas that fires a global Event when it starts, so that any FSM interested can listen to when the canvas will be activated.

- You don't deactivate the canvas, and instead you use CanvasGroup component, which allows you to hide it, and soft disable it, then it's alwasy active but not showing any content. https://docs.unity3d.com/Manual/class-CanvasGroup.html

Bye,

 Jean

Title: Re: What am I doing wrong?
Post by: PolyMad on October 05, 2018, 02:15:42 AM
Thank you Jean!
Good to know that finding by name is slow.
However I only use this action at the start of the map to activate the CANVAS, then no more!
Title: Re: What am I doing wrong?
Post by: PolyMad on October 05, 2018, 02:30:20 AM
What if I load the canvas calling it from a FSM?
Is it possible if the canvas is a prefab?
How do I add a GameObject to a scene? I can't find any action to do it.

Done it! CREATE OBJECT from the Ecosystem hurrah!!!
Title: Re: What am I doing wrong?
Post by: jeanfabre on October 05, 2018, 02:38:51 AM
Hi,

 Use the action CreateObject to add an object to a scene, can be a prefab or another object reference in the scene.

Bye,

 Jean
Title: Re: What am I doing wrong?
Post by: miguelfanclub on October 05, 2018, 06:31:18 AM
What I do is I do all the finds I want from one game object (+50 objects at the moment) and then I just get them via get game object FSM when needed.

So I make sure I only find them once.