playMaker

Author Topic: Is Create Object action - means Instantiate? [SOLVED]  (Read 3513 times)

Neikke

  • Full Member
  • ***
  • Posts: 134
Is Create Object action - means Instantiate? [SOLVED]
« on: June 14, 2019, 01:35:57 AM »
Hi, I'm developing a game for mobile platforms and since I have particles being created by Create Object action each time Player collides with Coins - I wanted ask if it really instantiates them which I heard to be a "no no" for mobile platforms? If it is, what would be the workaround then? Thanks!
« Last Edit: June 20, 2019, 06:19:18 AM by Neikke »

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: Is Create Object action - means Instantiate?
« Reply #1 on: June 18, 2019, 04:52:14 AM »
Sorry for bringing this up again, but I really would like to know.

I have simple particle effects that I span on Coins, Enemies. And I use "Create Object" as the main spawner of those particle effects whenever Player collides with them. So is it bad for Mobile Platforms? Thanks in advance!
« Last Edit: June 18, 2019, 04:57:21 AM by Neikke »

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: Is Create Object action - means Instantiate?
« Reply #2 on: June 18, 2019, 06:54:50 AM »
I thought I replied to this.

The Create Object is the 'bad one'. Basically it uses more memory when compared to  Pooling. How bad will depend on how many times you do it and other factors.

If you want it to be the best practice, you are meant to use a Pool for making lots of objects.

As far as I'm aware, you will need to use a third party extension (and playmaker actions made for it) to do pooling.

Maybe what you should do from this point is start googling "playmaker pooling" and see what you can find.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Is Create Object action - means Instantiate?
« Reply #3 on: June 18, 2019, 11:38:04 AM »
Hi.
The Action 'Create Object' is instantiating objects.
And if you need to use many times, its a "No No" for all platforms, not only for mobile.

As daniellogin mentioned Pooling is the best option for something like this, so you can reuse objects.

There is a package called Pooler on the Ecosystem that can be used for simple pooling.

This video explains well what pooling does :


Neikke

  • Full Member
  • ***
  • Posts: 134
Re: Is Create Object action - means Instantiate?
« Reply #4 on: June 19, 2019, 11:32:32 AM »
That's simply fantastic guys! Those Pooler actions work exactly as needed! Many thanks to you both daniellogin and djaydino!

One extra question. Here's my simple workflow:

1. As what I'm pooling is - popping up score numbers, I'm spawning those Score Numbers using 'Pooler Spawn' at the Player position.

3. Since I want those Score Numbers to be following Player - I'm also using "Set Parent" action to temporarily parent popping up Score Number to a Player. Otherwise when Player jumps or walks away - Score numbers just stay where they were spawned first.

3. After the Score Number has faded out, I unparent (Set Parent to: None) that pooled Score Number and doing Pooler Destroy Stored to deactivate this pooled score prefab and put it back to the Pool.

May be I'm overkilling it a bit but the question is - is this parenting/unparenting at runtime is also performance-friendly enough? Cos I'm doing the sequence I described here quite often when Player collides with coins for example, and sometimes he might collide with 5 or 10 coins in a row.

Thanks in advance!
« Last Edit: June 19, 2019, 11:37:28 AM by Neikke »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Is Create Object action - means Instantiate?
« Reply #5 on: June 19, 2019, 07:30:27 PM »
Hi.
im not sure how heavy or light parenting is, but maybe instead of parenting,
you can have a fsm on the coin handle this:

Use 'Set fsm Gameobject' and place the Gameobject that the coin needs to follow in a variable (target).

Then use 'Get Position' and as target place the 'target'. (every frame)
Store the position in a vector 3 (pos)

Then in the same state also use 'Set Position' to position the coin.
with the 'pos' variable. (every frame)

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: Is Create Object action - means Instantiate? [SOLVED]
« Reply #6 on: June 20, 2019, 06:19:05 AM »
Thanks a lot djaydino! To be honest I didn't understand why that Set FSM gameobject action was needed but it looks like I was able to solve it without this action. I solved it not on a Coin but on popping up ScoreNumber game object. Please have a look:

1. I just added Get Position action specifying that I want to get the position of my stored Player gameobject at runtime and store it in 'PlayerPosition' variable,

2. And then in the same state I added Set Position action setting the position of the owner (the ScoreNumber object) to be precisely at 'PlayerPosition' variable. This makes all pooled clones to be spawning exactly at my Player's position while they're active.

Once again thanks a lot!


« Last Edit: June 20, 2019, 06:21:08 AM by Neikke »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Is Create Object action - means Instantiate? [SOLVED]
« Reply #7 on: June 20, 2019, 10:58:48 AM »
Hi.
Just to be sure :
On Set Position you should set Space to 'World' in stead of 'Self'

Neikke

  • Full Member
  • ***
  • Posts: 134
Re: Is Create Object action - means Instantiate? [SOLVED]
« Reply #8 on: June 20, 2019, 11:41:35 AM »
Well since I have my Score prefab's coords set to 0 on all three axis, setting to World or Self didn't make any difference for me. But that's a good point to be aware of actually. Thanks a lot!

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: Is Create Object action - means Instantiate? [SOLVED]
« Reply #9 on: June 22, 2019, 03:29:18 AM »
I'll mention something about pooling, although maybe you already know:

You are reusing the same objects, and so can spawn with a 'hang over' from when you last used them. For example if you are using a rocket which moves via physics, it can spawn again with the same physics still being applied. So the first shot goes straight, you look to the left, then the next shot fires to the right, etc.

So for physics, right before you send the projectile back to the pool, set the velocities to 0 so you have a clean start when you spawn it again.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Is Create Object action - means Instantiate? [SOLVED]
« Reply #10 on: June 22, 2019, 08:24:14 AM »
Hi.
Indeed you need to "reset" variable values/movement/rotations/scale @ start or before despawining
i usually do this before despawning

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: Is Create Object action - means Instantiate? [SOLVED]
« Reply #11 on: June 22, 2019, 11:47:00 AM »
Hi.
Indeed you need to "reset" variable values/movement/rotations/scale @ start or before despawining
i usually do this before despawning
God dang it, I fricken jinxed myself.

So I'm adding a lobbed projectile right now. It spawns (at a 45 or so degree angle), has an impulse on Z, and also has torque applied to it's X. So it will sort of loft up and start arcing over.

The problem I am having is that it seems to be accumulating Torque each spawn. I have a Set Velocity for 0, 0, 0 right before it goes back to the pool, but that doesn't seem to work.

EDIT: Actually I found a work solution, although it seems a bit weird and indirect. I simply put a Is Kinematic on and then off at the start of the FSM before the new impulse and torque are added. That seems to work. Weirdly enough, when I tried to do the same thing just before repooling the object it didn't work.
« Last Edit: June 22, 2019, 11:58:53 AM by daniellogin »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Is Create Object action - means Instantiate? [SOLVED]
« Reply #12 on: June 22, 2019, 12:13:27 PM »
Hi.
You can also try "Set Angular Velocity" (Ecosystem) :)

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: Is Create Object action - means Instantiate? [SOLVED]
« Reply #13 on: June 22, 2019, 01:32:10 PM »
Hi.
You can also try "Set Angular Velocity" (Ecosystem) :)
OK thanks! That's actually what I want for this kind of thing. I was already wondering how to stop if from over-rotating (so the nose stops pitching when it's pointed straight down) and this looks like how (since, as established, the Set Velocity wouldn't stop an active roll, and setting to kinematic mid-flight would also not work).