playMaker

Author Topic: "Set Position" Bug  (Read 3765 times)

Davision

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
"Set Position" Bug
« on: July 18, 2012, 11:17:21 AM »
Til Set Position has been set it takes some time, or better said it runs through the next few states til the set position gets applied! I checked this with a raycast directly after the set position which failed and a raycast 1 second later which hit the object.
I took me some hours to figure out that there is a bug in "set position", it is crucial for my game that the set position gets applied directly because directly after it raycasts need check the playing field.

(Before it i used "create object" instead of setting position of objects that are already in the scene, a "create object" gets created before it runs through the next states.)

Davision

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: "Set Position" Bug
« Reply #1 on: July 21, 2012, 05:43:42 AM »
Is there a chance that this gets fixed in the the next version?

I tried to find a workaround for my game but everything i did wasnt good enough. The only proper workaround i could do is making a raycast loop for every object which has its position changed to check if the "set position" has been done and only then go in the next states to check the playing field. Obviously that would be a bit crazy and not fast enough.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3207
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: "Set Position" Bug
« Reply #2 on: July 21, 2012, 11:32:50 AM »
Are you using Every Frame or Late Update? With those unchecked it should apply the position immediately. Sometimes physics can interfere too... does the object have a Rigid Body?

Davision

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: "Set Position" Bug
« Reply #3 on: July 22, 2012, 06:23:02 AM »
I have both unchecked and my test proves that it does not apply the position immediately. It has only a simple box collision, or can only the box collision have a lag somehow?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3207
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: "Set Position" Bug
« Reply #4 on: July 22, 2012, 11:38:33 AM »
Try disabling it. The Set Position action is a very simple wrapper for a Unity command, but I'll double check it...

Davision

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: "Set Position" Bug
« Reply #5 on: July 22, 2012, 12:00:43 PM »
Try disabling the box collision? Then i can not test if the bug is still there. I need the box collision to do raycast check of the playing field right after its set to the new position. I also use a raycast the check bug, a raycast on the box collision to check if the set position has been done.

Did you try to recreate the bug? I could also make you a simple scene that shows the bug if you like?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3207
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: "Set Position" Bug
« Reply #6 on: July 22, 2012, 12:43:25 PM »
A simple scene would help - I cannot repro the bug here...

Not sure I understand how you're using raycast to debug this...? You could set a Breakpoint on a state and read the position in the Unity Inspector. Or use Get Position and Debug Log.

Are you sure the info you're getting from the raycast is correct. Sounds like a weird way to get an object's position. Raycasts ARE cached though, so that could be the problem.

Davision

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: "Set Position" Bug
« Reply #7 on: July 23, 2012, 06:59:31 AM »
Uploaded it here: www.tocogames.com//files/setpositionlag.zip
Its really simple, just make the wait time higher after the set position to see that is possible that the ray hits when there is enough time inbetween.

Breakpoints do not help in this case, i guess simply because they only stop at that state and not freeze the whole game.
Even if raycasts are cached and then calculate while it runs through the next states, it doesnt matter because the raycast is at the end of the logic.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3207
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: "Set Position" Bug
« Reply #8 on: July 23, 2012, 12:21:56 PM »
Thanks, got the file.

If I put Get Position and Debug Vector 3 on the Wait state, it prints (0,0,0) to the log. So Set Position seems to be working fine.

Which leads to the Raycast action. I wonder if there's some internal lag in Unity between the object position and the physics position... I tried switching Raycast to LateUpdate, but that didn't help. Very strange...

Will do some more digging...

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3207
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: "Set Position" Bug
« Reply #9 on: July 23, 2012, 12:57:20 PM »
It seems like Unity takes one frame to update the position of the Collider...? Maybe in the next FixedUpdate.

Is it critical to your design that the Raycast works the same frame as the Set Position?

Davision

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: "Set Position" Bug
« Reply #10 on: July 23, 2012, 01:44:36 PM »
If im save with a "next frame" action after the set position it should be fine. Would just take some more time til the next gems come in the playing field.

The fact that it worked just fine with "create object" instead of set position makes this especially strange for me, i would have understood if create object can take some calculation time and takes a frame or more but something simple like set position should be really instantly as a whole.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3207
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: "Set Position" Bug
« Reply #11 on: July 23, 2012, 02:46:33 PM »
I agree, it does seem odd.

I'll reproduce the test using a script, just to make sure it isn't a Playmaker issue...

Davision

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: "Set Position" Bug
« Reply #12 on: July 24, 2012, 07:30:39 AM »
I tried to fix it with a next frame action after the set position now, it did not work! But when i make 2x next frame action it works in the testscene i send you. However most of the time it doesnt work in my game with 2x next frame. So I think it must be performance that also plays a role here. That means then Im never really save with a delay or next frame actions after it. :(

I hope you can get some more insight in this with making a script.

Davision

  • Playmaker Newbie
  • *
  • Posts: 23
    • View Profile
Re: "Set Position" Bug
« Reply #13 on: July 31, 2012, 06:41:42 AM »
I found a workaround for the problem!
Deactivate the object, set position and then activate again. Then the collision is instantly there.
I just dont know how much performance the deactivate and activate could take, i guess it could matter on mobile with 56 times going though the loop.

Maybe you can make a tickbox for set position that makes sure that the collision is instantly there with deactivate/activate and maybe even make it more cheap performance wise?