playMaker

Author Topic: Understanding Array Get Next  (Read 4614 times)

PolyMad

  • Hero Member
  • *****
  • Posts: 545
Re: Understanding Array Get Next
« Reply #15 on: September 25, 2018, 03:39:26 AM »
OK, I'll try now, thank you.

But I'm not spawning a prefab, not now at least: the prefab is already in the scene, and the vehicle structure is already all built.
I just need to find the components (objects) in its hierarchy.

PolyMad

  • Hero Member
  • *****
  • Posts: 545
Re: Understanding Array Get Next
« Reply #16 on: September 25, 2018, 03:42:46 AM »
Wait, how do I do this?

"In the main parent from the prefab have an array with all the wheel objects. (name it 'wheels' for example)

Then when you spawn the object , store it in a variable."

I can't understand. I have already an array variable where I should store the wheels.
I have cut away all the part where the array was populated automatically, should I bring it back in?

That wasn't the problem, the problem was later, to extract the objects cyclically and apply the torque.

I don't have this type of problem, because I had already scripted the part to find the children and store them in the Array. It is an universal FSM that I will use as template on all vehicles.

The problem was later, in cycling through the array and applying the torque.
As the torque needs to be with the EVERY FRAME enabled, I can't keep the FSM cycling through the array.

My impression is that the arrays have been conceived in Playmaker as "slow action" variables to scan every now and then, and thus are not optimized to work in a continuous scanning situation.
« Last Edit: September 25, 2018, 03:45:37 AM by megmaltese »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Understanding Array Get Next
« Reply #17 on: September 25, 2018, 06:51:29 AM »
Hi,
Find and get child are slower (and not advisable to use) than placing them into an array.

The issue was not that it was to slow, but actually to fast.
if it loops more than 1000 times in a single frame you get the error.

with the array loop you should actually turn off every frame on the add torque, and the next frame event will handle the 'every frame'

You can use this on a separate fsm and use some global transitions to turn on/of the loop.
Here is a setup that should work :



But having a fsm with an add torque on each wheel and manipulate the speed with a set fsm float would be ok also.

PolyMad

  • Hero Member
  • *****
  • Posts: 545
Re: Understanding Array Get Next
« Reply #18 on: September 25, 2018, 01:01:13 PM »
Oh gosh, I almost can't believe I did it... I couldn't understand what the NEXT FRAME EVENT was for... now I know it  :o
I am using a simpler setup than yours, why have you set up so many entrance points and ping pong to other states?

« Last Edit: September 25, 2018, 01:15:22 PM by megmaltese »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Understanding Array Get Next
« Reply #19 on: September 26, 2018, 01:10:13 AM »
Hi.
Actually that setup is not good,

If your wheels are already set as a child before the game starts, you should drop them in the array manually, then you don't need to create the array at all as it is already set.

if the wheels are placed @ runtime, add them to the array on creation or at least give them at 'Tag' called Wheel so you can use "Game Object Compare Tag" instead of get name and string contains fast.

On the accelerate, what you do now is : set wheel 1, next frame, set wheel 2, next frame, and so on. all the wheels should be set 1st and then do next frame.

Also a loop action is not advisable to use in a single state, you can get bad/wrong behavior.

As for the key up/down it is also better to do this from a separate fsm.

In c# we do this also all the time as it zeros the chance of bad controls behavior.

PolyMad

  • Hero Member
  • *****
  • Posts: 545
Re: Understanding Array Get Next
« Reply #20 on: September 26, 2018, 06:11:00 AM »
Hi.
Actually that setup is not good,

If your wheels are already set as a child before the game starts, you should drop them in the array manually, then you don't need to create the array at all as it is already set.

if the wheels are placed @ runtime, add them to the array on creation or at least give them at 'Tag' called Wheel so you can use "Game Object Compare Tag" instead of get name and string contains fast.

It's what I am doing: at load map the array is filled with the wheels, so the script is universal and I don't need to fill it manually for each vehicle. It's all automated. I don't use the tag and I prefer to scan for objects' names (wheel + COLL) to find the relevant objects, so I leave tags out of this.



Quote
On the accelerate, what you do now is : set wheel 1, next frame, set wheel 2, next frame, and so on. all the wheels should be set 1st and then do next frame.

Uhhh I will have to think about this a while  ;D



Quote
Also a loop action is not advisable to use in a single state, you can get bad/wrong behavior.

And more on this as well  ;D ;D ;D



Quote
As for the key up/down it is also better to do this from a separate fsm.

In c# we do this also all the time as it zeros the chance of bad controls behavior.

In effect I've seen that some times the GET KEY UP is "lost" for some reason...

Thank you very much for your help!