playMaker

Author Topic: Create or activate game object when spawning, which is best?  (Read 1166 times)

Maddy

  • Playmaker Newbie
  • *
  • Posts: 34
I have a menu page with levels and a "Complete Level Image" for each completed level. Which is best...

1. Have the Completed Images be activated at runtime and have them activate every frame? The images are deactivated at the start and checked if there are enough points for each level, if there are enough points, then the image is activated.

or 2. Create each Completed Image at runtime if there are enough points?

2D mobile game.

Thanks in advance!
I'm an artist with poor memory and brain fog trying to make a game. Please wish me luck! :-D

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: Create or activate game object when spawning, which is best?
« Reply #1 on: July 11, 2019, 01:33:07 PM »
Creating objects is very performance heavy and usually not recommended especially for mobile platforms. Activating/deactivating in my opinion would be best.

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Create or activate game object when spawning, which is best?
« Reply #2 on: July 12, 2019, 02:58:07 AM »
It probably won’t matter whether you pool or create/destroy in this case, but of course it all adds up. I’d be more concerned with the “every frame”, because it doesn’t seem like you need it. You can update the UI when opening the menu.

If you need to update the UI more often, consider how twitchy it really has to be. Menus can probably update once a second, and nobody notices it. If it needs to be more responsive, you can go to 0.2 which is on the threshold of perception. Higher values are needed for action-driven gameplay, where frames matter because you directly feel the consequences.

Maddy

  • Playmaker Newbie
  • *
  • Posts: 34
Re: Create or activate game object when spawning, which is best?
« Reply #3 on: July 13, 2019, 05:26:36 AM »
Thanks Neikke and Thore!

@Thore, I've set it to Every Frame in the check box, otherwise it won't show. The reason I was wondering if it would be better to use Create Object, was just the updating every frame.

You wrote: "You can update the UI when opening the menu." How do you mean specifically?

The images that I need on the menu page will be activated/created as each level is completed and is static. Or maybe I should call it the levels page, because it's where I have thumbs for all the levels.

To have the images update less frequently, what do I use for that?

Thanks!
I'm an artist with poor memory and brain fog trying to make a game. Please wish me luck! :-D

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Create or activate game object when spawning, which is best?
« Reply #4 on: July 13, 2019, 08:06:27 AM »
Hi.
In general things (like images or text for example) that are not changed every frame, are best only to update on changes.

For example if you would have your points displayed with a text object.
You can use 'float changed' or 'int changed' and only do 'ui text set text' (or textmesh version) when the value has changed.

Creating objects @runtime are best done @ start of the game if possible,
especially when you need to create multiple objects at the same time.

When you create @start you can store the objects into variables or arrays to reference them.

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Create or activate game object when spawning, which is best?
« Reply #5 on: July 13, 2019, 08:19:34 AM »
Thanks Neikke and Thore!

@Thore, I've set it to Every Frame in the check box, otherwise it won't show. The reason I was wondering if it would be better to use Create Object, was just the updating every frame.

You wrote: "You can update the UI when opening the menu." How do you mean specifically?

The images that I need on the menu page will be activated/created as each level is completed and is static. Or maybe I should call it the levels page, because it's where I have thumbs for all the levels.

To have the images update less frequently, what do I use for that?

Thanks!

One way to do this is to make a global event, say "UI/UPDATE" (this nests it in the list). Then, at the point where the menu is called up, e.g. when the player presses a button, you send this event before it shows the menu. In the menu that sets it all up, right click on the state > Global Transition > Custom Events > UI > UPDATE (the latter two as you defined above).

If you want another frequency than every frame, you can create a short loop. First, you separate all the actions that need to run once @Start or somewhere close afterwards. Then, the actions that need to update periodically, go into their own state (or series of states) to run once, too. But at the end of the run, you add an additional state, e.g. "loop" and put a wait action into it. Put the wait time into a variable so you can adjust it easily later on, and then connect the wait event (typically finish), to the beginning of the intended loop, so that the actions run again once, and again, and so on. Can also be done in a super condensed version by putting it all in one state, and have a wait event loop into the same state. Be sure you default a wait value greater than 0, or it will complain.