Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: DanielThomas on March 17, 2018, 03:00:25 PM

Title: Prefab Create object uses old collider
Post by: DanielThomas on March 17, 2018, 03:00:25 PM
I got a problem using collider2D. I have buildings as prefabs and you can place them down in the scene.

In Playmaker I create an game object from the prefab, I do "on enter" and "on exit" actions on it. (to see if it can be placed on ground) This works so far. I place it down. But when I create a new game object (using same FSM and actions) from the same prefab it's getting weird, the collider used for test is the first game object. So the collision test is true or false based on if the first game object I had is colliding - not the new GO I created.

Is this someone seen before?
Title: Re: Prefab Create object uses old collider
Post by: DanielThomas on March 17, 2018, 05:51:32 PM
Here's some visual hints, the FSM is cleaned down to the bare bone to isolate the problem.

(http://www.danielthomasart.com/Uploads/Images/collider1.jpg)
(http://www.danielthomasart.com/Uploads/Images/collider2.jpg)


EDIT: I also tried have a different gameobject prefab created after the first one, it still use the first GO collider. I looked a little in the action script of trigger2D event but don't understand all of it, is there a chance the collider is cached and don't update or something?
Title: Re: Prefab Create object uses old collider
Post by: djaydino on March 19, 2018, 06:17:25 PM
Hi.
It might be better to use 'On Trigger Stay' instead of 'On Trigger Enter'
and you can find some actions on the Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181) to set the color instead of using set property

Now i do think you setup is wrong, try this :

After 'Create GameObject' use the 2 trigger events only once to know on spawn if it can place or can't. and remove the Get Fire1 Down action

Then in reset color add a trigger2D Event (On Trigger Exit) and conntect to 'Can't Place'
Also add the 'Get Fire1 Down' and connect to 'has building'.

Then in 'Can't Place add a trigger2D Event (On Trigger Stay) and connect to 'reset color'

I hope you understand, if not let me know and i will make a sample tomorrow.
Title: Re: Prefab Create object uses old collider
Post by: DanielThomas on March 19, 2018, 08:45:13 PM
I tried but same result. The first created object is the one giving the collision result.
I also tried in a fresh new project and got same result.
What I'm doing in short, tried in a fresh project:
I have a prefab with sprite renderer, box collider(set to trigger) and a rigidbody2D(no gravity).
I have an empty object in the scene with the FSM.

- Start
"Create Object". Store in gameobject variable
with stored gameobject Use Trigger2D stay and exit between two states
I click and I restart and go to - Start state.

I redo the FSM loop a few times to just have objects to collide with. The last object I have while the FSM is looping through the trigger tests doesn't make the triggers fire. If I now grab the first object I created with the FSM and move it around - THIS makes the fsm fire the trigger event - even though it's not currently stored in the game object  variable that's used in the trigger action.

Anyone else who can reproduce this? It must be a problem with the action since I try with a fresh project and it's just a few actions.

Let me know.
Title: Re: Prefab Create object uses old collider
Post by: djaydino on March 20, 2018, 07:58:21 AM
Hi, could you pm a link to the project so i can test and try to find a solutior (or to confirm that it is a bug.
Title: Re: Prefab Create object uses old collider
Post by: djaydino on March 20, 2018, 01:30:42 PM
Hi,
There seems indeed to be some issues with this. could you send a bug report in unity?
You can find it in the menu: playmaker/tools/submit bug report

i will also contact alex.

Meanwhile i cooked up a solution by placing the trigger events on the prefab.

You can get the package below and add it to your test project or to any project to test. i have also kept yours in it, so if anyone else would like to test they can :)

Project needs playmaker to be installed ofc.

To test, click somewhere in the game to spawn a circle, then spawn a 2nd one and move it around by changing values on inspector then a 3rd for there you can see the issue.
Title: Re: Prefab Create object uses old collider
Post by: DanielThomas on March 20, 2018, 03:23:38 PM
Bug report email, hopefully it something easy.
The solution works, thanks! Good to know it can be worked around while waiting for a fix.
Title: Re: Prefab Create object uses old collider
Post by: djaydino on March 20, 2018, 04:57:41 PM
Hi.
On older version triggers/colliders always had to be on the owner.

And it still is better than redirecting, as it works slower that on owner (only noticeable with large amount used simultaneously)