Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: PolyMad on September 11, 2018, 01:04:38 AM

Title: Understanding Array Get Next
Post by: PolyMad on September 11, 2018, 01:04:38 AM
I have a state where an Array that contains all the wheels of a vehicle is scanned, and another action adds torque to the wheels, but I can't understand how to make it work properly.
If the loop is active, it seems the array will work inside itself until it's over, then move onto the next action with just the last selected object.
On the other side, if I try anything different, I will occur into other problems, like excess loops or inefficiency because of switching states... I think this all should happen in a single state.

I think I should not use the LOOP inside the Array Get Next, but do it after the torque has been applied, but there's no LOOP action to add.
In fact, if I remove the LOOP at the Array Get Next action, only the first wheel will rotate, while with LOOP active, only the last wheel rotates.
How do I solve this thing?
Title: Re: Understanding Array Get Next
Post by: jeanfabre on September 11, 2018, 04:11:53 AM
Hi,

 you need to have your arrayGetNext on its own in the state, and transition using Loop and Finished event event  to move to other states.

in the Loop state, you do all you need to to do for the given item passed from the action ArrayGetNext ( the result field).

 does that make sense?

Bye,

 Jean
Title: Re: Understanding Array Get Next
Post by: PolyMad on September 11, 2018, 07:13:23 AM
Did as you suggested, but I also have to put a "RELOOP" at the end of the "FINISH" transition in the ARRAY GET NEXT, as the state should not exit until the player releases the button, it's not that I want to leave the state after the loop is done, this loop must be done as much as the player doesn't release the key.
Title: Re: Understanding Array Get Next
Post by: PolyMad on September 11, 2018, 07:16:32 AM
I am afraid Playmaker doesn't get this situation in solution and at the moment this can only be made by setting up 8 variables (wheels can be up to 8 ) and the related number of ADD TORQUE actions for each variable in a state :( and eliminating completely the ARRAY GET NEXT action.
Title: Re: Understanding Array Get Next
Post by: jeanfabre on September 11, 2018, 10:30:06 AM
Hi,

 do you mean you want to add force every update on all objects in an Array, in one state?

and it doesn't work if you use multiple states?

 Bye,

 Jean
Title: Re: Understanding Array Get Next
Post by: PolyMad on September 11, 2018, 11:33:39 AM
Have you seen the screenshots?
With that setup I get the "too many loops" error.
Title: Re: Understanding Array Get Next
Post by: jeanfabre on September 12, 2018, 01:13:16 AM
Hi,

 yes, because you do that without waiting the next frame once you have finished looping.

 looping an array takes less time than the length of a frame, so once you have finished looping, go to a state with a next frame event, and start again the next frame.

your screenshot is confusing because you are using the loop event it seems. and so it's not clear with just that screenshot what you want to achieve in terms of flow.

 Bye,

 Jean
Title: Re: Understanding Array Get Next
Post by: PolyMad on September 12, 2018, 08:39:35 AM
OK.

Btw, I have a situation now where I can't drag an GameObject to a field that waits for a GameObject.
Any idea why this is happening?
The field is red, waiting for a GameObject, but when I drag it there, it remains unresponsive.
Never happened before.
The action is ADD TORQUE, but I suspect this is global. Going to check it now.

It's global, it's official: I can't anymore select objects by grabbing them onto actions.
Any idea what can cause this? --- Just tried in another project and it works. Uffffff...
Title: Re: Understanding Array Get Next
Post by: djaydino on September 13, 2018, 01:37:22 AM
Hi.
It is because your fsm is a template.

They are like prefabs on your project folder, they can't communicate directly to scene objects.

What playmaker version are you using?

normally it should show an error message :

(https://i.imgur.com/Rpr3Rqxl.png)
Title: Re: Understanding Array Get Next
Post by: jeanfabre on September 13, 2018, 02:47:13 AM
Hi,

 yes, I was about to say, it's because you are editing the template itself, make a variable, expose it to the inspector, and then from the fsm that uses this template you can reference as usual .

warning, refresh your fsm using your template when you change the variable inspector flag, and watch out for mixed up vars, there is a known bug where inspector variables may get mixed up as you add more of the same type, and references can get swapped between variables exposed to the inspector.

 Bye,

 Jean
Title: Re: Understanding Array Get Next
Post by: PolyMad on September 13, 2018, 03:36:00 PM
Uhm, it's strange, because I'm working with templates since days and I didn't meet this problem before... I'll keep you informed.
Title: Re: Understanding Array Get Next
Post by: PolyMad on September 24, 2018, 04:20:36 PM
Back on track!

Soooo...

I am afraid Playmaker doesn't get this situation in solution and at the moment this can only be made by setting up 8 variables (wheels can be up to 8 ) and the related number of ADD TORQUE actions for each variable in a state :( and eliminating completely the ARRAY GET NEXT action.

Any idea on how I could solve this?
Scan through an array and apply torque each frame on each of the objects in the array?
It goes into loop count exceeded error.

If I put an Array Get for each of the wheel, then there's another problem: the Array Get only gets done one time in the state, while the Add Torque gets done continuously at each frame.
And then I exit when the player releases the key.
I can't see any way to make it work by using an array of objects.

The only way that comes to my mind for now is to strip away the loop cycle through the array, put all the wheel objects in their respective variables (wheel 1, wheel 2, etc.) at the beginning of the FSM, and then have a state where the torque is applied to all these objects with direct link to the variable... but this would be really ugly to see and maintain.

Can you please help?
I think this is a case that should be handled by Playmaker, while at the moment I don't think it can.

I can send you the package so you better understand the problem.
Title: Re: Understanding Array Get Next
Post by: djaydino on September 25, 2018, 02:44:43 AM
hi,
You can add a state with a 'next frame event' after the finished event (from the array get next)

The 'add torque' should only happen once every frame (on each object)
Without the 'next frame event' it keeps looping and standard, the loop limit is set to 1000 (which can be override in the Fsm tab, but not recommended in this case)
Title: Re: Understanding Array Get Next
Post by: PolyMad on September 25, 2018, 03:16:07 AM
I still can't understand how all this flow should work, so maybe better I look for a simpler solution.

I was trying to use the HAS CHILD action, but it's not recursive.

The only RECURSIVE action available is GET NEXT CHILD RECURSIVE... and this will have me again produce 8 repeating flows to store the 8 wheels into their variables.

The ideal would be an action HAS CHILD RECURSIVE, so that I could just write the name in there and it would scan all the children and store the object right away.



Sorry for asking, but am I the only one who needs such complex actions?

I'm sorry to annoy you, but I am on a game where the vehicles can have an elastic configuration and the various parts can be "anywhere" in the hierarchy, and in a variable number from 4 to 8... so I need a recursive system to trace the objects without getting mad!
Title: Re: Understanding Array Get Next
Post by: djaydino on September 25, 2018, 03:27:12 AM
Hi.
From what i understand you are spawning a prefab and need to get the wheels right?

Don't use the has child or get next child.

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.
Then use 'get fsm array' to get 'wheels' array on the prefab.

if you have different vehicles use the same array name for the wheels.
Title: Re: Understanding Array Get Next
Post by: PolyMad 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.
Title: Re: Understanding Array Get Next
Post by: PolyMad 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.
Title: Re: Understanding Array Get Next
Post by: djaydino 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 :

(https://i.imgur.com/NKJwTXA.gif)

But having a fsm with an add torque on each wheel and manipulate the speed with a set fsm float would be ok also.
Title: Re: Understanding Array Get Next
Post by: PolyMad 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?

Title: Re: Understanding Array Get Next
Post by: djaydino 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.
Title: Re: Understanding Array Get Next
Post by: PolyMad 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!