playMaker

Author Topic: Prefab Create object uses old collider  (Read 1080 times)

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 124
    • View Profile
Prefab Create object uses old collider
« on: March 17, 2018, 12: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?
« Last Edit: March 17, 2018, 02:13:13 PM by DanielThomas »

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 124
    • View Profile
Re: Prefab Create object uses old collider
« Reply #1 on: March 17, 2018, 02:51:32 PM »
Here's some visual hints, the FSM is cleaned down to the bare bone to isolate the problem.





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?
« Last Edit: March 17, 2018, 03:38:06 PM by DanielThomas »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4428
    • View Profile
    • jinxtergames
Re: Prefab Create object uses old collider
« Reply #2 on: March 19, 2018, 03: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 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.
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 124
    • View Profile
Re: Prefab Create object uses old collider
« Reply #3 on: March 19, 2018, 05: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.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4428
    • View Profile
    • jinxtergames
Re: Prefab Create object uses old collider
« Reply #4 on: March 20, 2018, 04: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.
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4428
    • View Profile
    • jinxtergames
Re: Prefab Create object uses old collider
« Reply #5 on: March 20, 2018, 10:30:42 AM »
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.
« Last Edit: March 20, 2018, 10:40:49 AM by djaydino »
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 124
    • View Profile
Re: Prefab Create object uses old collider
« Reply #6 on: March 20, 2018, 12: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.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4428
    • View Profile
    • jinxtergames
Re: Prefab Create object uses old collider
« Reply #7 on: March 20, 2018, 01: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)
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions