#Installing Unity Physics package breaks my logic

1 messages · Page 1 of 1 (latest)

grizzled haven
#

I can not make this up. The simple act of installing the Physics package to handle physics in ECS breaks part of the scene for some reason. Let me walk you through what is happening:

  • User selects gun
  • A gun is instantiated per player on screen on their hand (child GO of player)
  • Each gun has a muzzle (child GO of gun) from which the bullet comes out of.
  • Before installing package, everything works fine
  • After installing package, all guns seem to appear at world center ignoring player movement
  • Even though the guns are at world center, the bullets are coming out of the "correct" position, where the muzzle of the gun would be, it even reacts to the player movement
  • Uninstalling the package fixes the issue instantly

I have tested this + closing the editor and reponening + making a build and its constant in all cases. Is there a system from the physics package i am not aware of that runs in the background that is causing this?

I can share all necesary code. Thank you!

spark abyss
#

do you have physics colliders on your guns?

grizzled haven
#

i do not, since they wont really be colliding with anything

#

should they?

spark abyss
#

it looks like they're being deparented

#

which is what physics package does to child colliders

grizzled haven
#

i just added a collider to my guns and its working????

#

how on earth does that make any sense lmao

spark abyss
#

oh i suspect you haven't given your guns any transform flags so since your objects are in a subscene they're being deparented for optimization

#

this is kind of, unexpected behaviour tbh

#

if you remove the collider, make them prefabs and spawn at runtime do they work as well?

grizzled haven
#

it does not. My setup is actually as follows:

  • I have a group of weapons as perfabs without colliders
  • Have them stored in scriptable objects
  • Have an Authoring script in my WeaponsDatabase Subscene that references these scriptableobjects and bakes all the prefabs
  • I select the weapon in runtime and spawn them as entities as children of the player's weapon holder

What didnt work was precisely NOT having a collider on the root of the weapon. If i remove it, it breaks

#

i find that deparenting behaviour strange, why would it do that when i explicitly parent it?

grizzled haven
#

okay, after processing this information, i kind of woke up with the answer as to how the weapons were unparented but the shooting was done correctly:

The weapon prefabs are now basic cubes, all children of an empty GO. The hierarchy goes like this:

WeaponEmptyGO->ModelEmptyGO-> Cubes
WeaponEmptyGO->MuzzleEmptyGO

What was really happening is that my weapons did not have a collider at WeaponEmptyGO, but the default cubes did (because i never removed their default box collider). So the Cubes were getting deparented from the ModelEmptyGO, but the rest of the body with the muzzle was getting placed correctly.

The correct fix wasnt to add another collider to the WeaponEmptyGO, but to remove the colliders from the cubes