playMaker

Author Topic: List of actions that are "bad" & tutorial for pooler in ecosystem  (Read 1318 times)

Nim

  • Playmaker Newbie
  • *
  • Posts: 9
Hi. Could somebody please help on below questions:
1. I heard that there are some actions that are "bad" because it use more memory, example "create object" (refer to this link https://hutonggames.com/playmakerforum/index.php?topic=20672.0).

Is there any way to know the list of actions that are "bad" & can cause performance issue? I'm new in Playmaker & don't know coding at all. So please pardon my stupid question & it'll be helpful to have more specific detail on the action.

2. Can I know where to get the tutorial for using pooler in ecosystem? Can't seem to find it from the official Hutong Youtube nor from other people. I notice there is brackey's pooling tutorial (scripting), however I can't seem to understand it when applied in Playmaker.  :(

Thank you.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: List of actions that are "bad" & tutorial for pooler in ecosystem
« Reply #1 on: February 22, 2021, 06:17:35 PM »
Hi.
Create/destroy object are indeed resource heavy. but if you have to do this for objects only used once, best to do on start of the scene. (create)

pooler is not an official package :)

pooler pool is to create a pool from a prefab.
on it you can do some settings like 'Initially Pooled Objects'
with this you can preload a mount of the prefab.
to set the amount for this, calculate how many of the same prefab would be active at the same time.

if you hover over the variables it should show some information on what it does.

Use poolerSpawn to spawn a prefab from the pool.

Then use Pooler Destroy Self or Pooler Destroy Stored to disable the prefab

Pooler Destroy Pool will destroy the pool.

I am using pooler in this tutorial :


Nim

  • Playmaker Newbie
  • *
  • Posts: 9
Re: List of actions that are "bad" & tutorial for pooler in ecosystem
« Reply #2 on: February 23, 2021, 01:21:25 AM »
djaydino, thanks a lot for your explanation. Is there any other actions that are resource heavy as well?

Also, another question what would be best practice if want to create "inspecting item" function. I mean the character will be able to inspect/ search items inside let's say a table, whenever he looks at the item. Whenever he looks at the table, "search" text will appear & he can further inspect it. But when he looks away, no "search" text appear. He may keep looking at the table on & off. In this case, is using "create object" good practice?

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: List of actions that are "bad" & tutorial for pooler in ecosystem
« Reply #3 on: February 23, 2021, 02:41:16 AM »
Find Game Object is expensive. Actually, I think any action with the word 'Find' should be avoided as it instigates searching through the entire object list/hierarchy to get the result.

I used to use Find Game Object as a quick and easy way of setting variables on spawned prefabs (which is something you're looking into, right?), and ended up re-working all my prefabs so the variables are set in the same action immediately after the pooler spawn action.

For example: You want to spawn a wave of enemies that move towards your player, and each enemy starts as a blank page as a prefab cannot reference variables (in my case, objects) outside of its prefab state. So you need to set the player spaceship as an object variable on the prefab for either Move Towards>Player, or Look At>Player etc. The temptation is to add a Find Game Object (Player) as the first action on the prefab, as it's quick and easy.

The most efficient way is to use Set FSM Game Object (or Set FSM Int, Float, Bool etc, depending on your needs) -



You can se in this example, that when I've spawned the prefab (enemy), the object is stored as a variable 'droneWave', and then I've used Set FSM Game Object to give 'droneWave' the variables it needs. You can see in this example I've got a whole bunch of Set FSM Game Object actions stacked up, so imagine if every variable was set using Find Game Object instead, each time an enemy wave is spawned.

It can be a bit fiddly and time consuming, but is the most direct and efficient line of communication.
« Last Edit: February 23, 2021, 03:01:53 AM by curb47 »

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: List of actions that are "bad" & tutorial for pooler in ecosystem
« Reply #4 on: February 23, 2021, 03:00:28 AM »
Broadcast All is another one you want to avoid. You'll discover this on the Send Event action, in the Event Target parameter. Basically, it's a quick and easy way of triggering events on any object/FSM that has a particular Global Event.

I guess it has the same price as Find Game Object, as the Broadcast All has to search the entire hierarchy to make sure it's targeted all the FSMs with the corresponding Global Event.

I used to use this a lot, before I discovered Arrays. After you've gotten your head around Pooling/Spawning etc, the next best thing you could get into is Arrays. Array Maker on the eco system is the go-to set of actions for this.

Generally, it enables you to store objects/variables to a dynamic list, and if you need to send an event to a bunch of objects, use can send the event to specific lists.


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: List of actions that are "bad" & tutorial for pooler in ecosystem
« Reply #5 on: February 23, 2021, 06:14:20 AM »

Also, another question what would be best practice if want to create "inspecting item" function. I mean the character will be able to inspect/ search items inside let's say a table, whenever he looks at the item. Whenever he looks at the table, "search" text will appear & he can further inspect it. But when he looks away, no "search" text appear. He may keep looking at the table on & off. In this case, is using "create object" good practice?
Hi.
No, "create object" would be a bad way to do this.
What you can do is Disable/Enable The Text object, or set the Alpha(color) to 0/1

When you alpha you can also tween the float to show/hide more smoothly.

is your project for 2D, 3D or VR?

Nim

  • Playmaker Newbie
  • *
  • Posts: 9
Re: List of actions that are "bad" & tutorial for pooler in ecosystem
« Reply #6 on: February 24, 2021, 04:53:09 AM »
Thanks curb47 & djaydino for sharing. I'll take note in future. I need more time to digest what you say ;D

I'm actually in the middle of youtube tutorial in making 3D horror game. But sometimes he kept changing the method, which make me super confused. So I'd like to create my own version for some parts. BTW, do Spherecase, get raycast, get/ set tag, conditional expression are heavy resources too? He uses a lot of this.

For the "inspecting item" function I mention previously, could you advice how I can do it? I want to make a logic like below:
1. Is player looking at the object? => use spherecast
2. If yes, check if the object tag is "door".
3. If yes, activate "text" gameobject & set the text with "UI Text set text"
4. When the UI text appear, player can get key down to make interaction
5. The interaction will show animation e.g. door opening or door closing
6. The current state of the door will determine what animation it will play. e.g. if currently door is closed, it will play door opening animation, vice versa

For no 1, 2 & 3 I can get the answer by following the tutorial. But I don't know how to know which animation / door state currently is so that the animation can play accordingly when I click a button.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: List of actions that are "bad" & tutorial for pooler in ecosystem
« Reply #7 on: February 24, 2021, 05:05:48 AM »
Hi.
Casts are not as heavy as find/create/destroy, but if you do not need to do it every frame you should not.

I our game the enemies use box casts and in front they 'look' every 4 frames
and behind they 'look' between 0.3 sec and 0.5 sec

Most cast action have a interval you can set or you can cast 1ce (interval 0) and then do a wait and cast again.

Trigger events can also bee costly when used a lot.

For example if you would have coins to pick up.
Then you should have a trigger event or box cast on player to detect them and not have trigger events on the coins.

Nim

  • Playmaker Newbie
  • *
  • Posts: 9
Re: List of actions that are "bad" & tutorial for pooler in ecosystem
« Reply #8 on: February 25, 2021, 04:31:54 AM »
I see. What about how to set up logic to know which animation / door state currently is at? so that when player interacts with the door, the door animation can play accordingly (if it's closed, it will play door open animation & vice versa)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: List of actions that are "bad" & tutorial for pooler in ecosystem
« Reply #9 on: February 25, 2021, 06:31:34 AM »
Hi.
That depends on your games as you can go several ways with this.

for example if player needs to open the door (for example by pressing a button / key)
Then you can use for example a overlap box (Ecosystem on player.
which can get objects, then check tag and if tag is (for example) 'Door/Manual'
Send a event to the door. (on the door you could use a bool flip, then a bool test to know if it should open or close)

When the door should automatically open then you should have a trigger on the door itself.
Here you can make a object with a collider (set as trigger) larger than the door ann
use trigger events (on stay / on exit)
on stay open door, on exit close.

Usually when i use triggers, i set a separate fsm with 2 states :
in state 1 a trigger event (stay) and a set bool (false)
in state 2 a trigger event (exit) and a set bool (true)

Then on the other fsm i use a 'Fsm Bool Test' to look if in trigger or not.

The reason for this is because when player exits the trigger and the state that has a trigger event exit is not active, it will not register when it reaches that state.

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 254
Re: List of actions that are "bad" & tutorial for pooler in ecosystem
« Reply #10 on: February 27, 2021, 07:58:13 PM »
Interesting thread and thanks for all the information.

I sometimes have an event that needs to get sent to 3-5 different FSMs (on 2-3 different game objects). I kinda thought that doing 5 consecutive send event actions in the same state was causing a small lag, hence I converted this into one broadcast all event. I do this like 2-3 times in my entire game. For example load new level is such an event and it affects several FSMs on the playermanager, gamemanager and uimanager.

I haven't thought of the option to do it with an array. Would array be better than 5 consecutive send event actions? I pretty much was lazy to do it with a loop because it's 'only' 3-5 events.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: List of actions that are "bad" & tutorial for pooler in ecosystem
« Reply #11 on: February 27, 2021, 08:32:37 PM »
Hi
The send events should not give lag.
the fsms that receive the event could cause lag, for example if all of them would create an object.

in such a case you might want to loop thru an array and use a next frame event so they are not called on the same frame.