Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Bug NetworkTransform and parent scaled to 0

Discussion in 'Netcode for GameObjects' started by unnanego, Mar 27, 2024.

  1. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    203
    I have an object with a NetworkTransform, which has some children at different localPositions also with NetworkTransforms. The parent is scaled to 0,0,0.

    The problem is, when I scale the parent back to 1,1,1, the children on the clients are all at position zero. Is there a way to prevent this?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,472
    How were the children parented? In-scene placed, spawned prefab, or individually spawned and moved to new parent?

    Do the children have NetworkObjects too?
     
    unnanego likes this.
  3. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    203
    It's the same behaviour both when it's in scene and when prefab. The children are not spawned/reparented and they have their own NetworkTransforms
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,472
    could you post Inspector screenshots of the parent and child network transforms?
     
    unnanego likes this.
  5. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    203
    Parent:
    Screenshot 2024-03-28 at 10.07.20.png

    Children:
    Screenshot 2024-03-28 at 10.07.07.png
     
  6. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,472
    Try setting the parent networktransform to use world space. Or both. Or the opposite: child in world space.

    I had issues with this combo and overriding the same sync values in the child, eventually I settled to synchronizing the child myself with a netvar since it was only the up/down look rotation (head follows firstperson view).
     
    unnanego likes this.
  7. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    203
    I can't, it's used in an AR multiplayer project and for all the users the world space position would be different, everything has to be in local space for localization purposes
     
  8. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,472
    Not sure I understand these implications, or how this relates to localization (as in language, not position).

    I assume this means the prefab is also parented to different, client-specific network objects?

    Maybe you can't prevent the scale change but you could send an RPC when you scale, so that the owner(s) can reset their scale values to be 1,1,1 again. You could also unparent the child temporarily, apply scale, and reparent to see if that makes any difference.

    Also it may be worthwhile to reconstruct this setup in a non-networked scene just to see if scaling the parent has the same effect on its children. If so, there must be an explanation for this behaviour. For instance when you drag a 1,1,1 scaled object to a parent that's 2,2,2 scaled, the dragged child will change its scale to .5,.5,.5. But when the parent's scale is 0,0,0 this may somehow affect the child positions due to "0 times something equals zero". Just a hunch. It may make a difference to scale to 0.00001 instead of flat 0s, you could give that a try too.
     
  9. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    203
    We are using image tracking to align content between different AR headsets - so if I unparent anything and it becomes in world space, it will be in different position for every user, because for every user the zero point of the scene is in a different place (where their headset was when the app was started), so that is not an option((( Scaling not to 0, but to 0.01f also doesn't help - the positions are at 0.00007 instead of 0.07, for example, when it's scaled up.

    Important thing to point out - everything works as intended on the server, it's only happening on the clients. And it's impossible to apply scale on the clients, since it requires changing ownership, which is not possible when there are many clients at the same time.