Commit 64c4331
fix: Parenting does not preserve WorldPositionStays option and other parenting related issues (#2146)
* fix
Parenting:
Fixed the issue where WorldPositionStays was not being synchronized with clients.
Removed m_IsReparented and associated properties.
Added world position stays parameter to CreateLocalNetworkObject to preserve worldPostionStays.
This fixes some edge case scenarios and issues with parenting in-scene placed NetworkObjects.
One in particular is to provide the local space position and rotation in ParentSyncMessage if the WorldPositionStays value is false. The server might maintain the original local space values and upon being reparented it re-applies the local space values. This is only pertinent if the user decides they don't want to use a NetworkTransform for the NetworkObject in question.
Now, a users can control what the final position, rotation, and scale of a NetworkObject is when being added/removed to/from a parent's sibling list ("parented or de-parented").
Parenting and Scale:
Fixed issue where GetMessageSceneObject wasn't using the NetworkObject's lossy scale value. This would result in improper scaling of parented (WorldPositionStays = true) child NetworkObjects for late joining clients. Added comments with details on this.
Fixed edge case scenario where nested in-scene placed NetworkObject children are de-parented and then a client late joins. Under this scenario (only for in-scene placed NetworkObjects) we want the late joining client to remove its parent, then set the transform values, and then get spawned.
NetworkTransform:
Fixed issue where TryCommitTransformToServer was not honoring the NetworkTransform.InLocalSpace property.
Fixed issue where teleporting did not honor the NetworkTransforms's current synchronize axis settings.
Removed the private m_TickFrequency property as it is no longer being used.
* refactor
CreateLocalNetworkObject now just accepts the NetworkObject.SceneObject structure as opposed to the 10 properties of the NetworkObject.SceneObject structure passed in as parameters.
Provided the ability to invoke NetworkObject.TrySetParent with a null value in order to be able to remove a parent while also selecting whether they want WorldPositionStay to be true or false (when removing a parent WorldPositionStays impacts the final transform values and can lead to scale issue if you parent with WorldPositionStays set to false and then it remove the parent with WorldPositionStays set to true).
Consolidated the CreateLocalNetworkObject's assignment of the transform values, parenting, and DDOL migration.
Removed parenting from CreateLocalNetworkObject
Removed setting the cached parent directly within SpawnNetworkObjectLocallyCommon as this is done within NetworkObject.ApplyNetworkParenting.
* add
Added RemoveParent to the ParentSync message.
Added applying scale to CreateLocalNetworkObject.
Added parent child sorting to the SceneEventData's synchronization serialization process.
Added the TryRemoveParent helper method to make removing a parent easier. Without this method users will have to use TrySetParent and cast the null value to either GameObject or NetworkObject.
* test
Added ParentingWorldPositionStaysTest:
Testing with and without WorldPositionStays while also varying child position, rotation, and scale values.
Validates scale with multi-generation nested children where most of the parents have a scale other than Vector3.one.
Created abstract IntegrationTestWithApproximation to avoid replicating the exact same set of Approximately methods.
Added ParentingInSceneObjectsTests:
This includes all of the scripts and assets that the ParentingInSceneObjectsTests needs.
It includes adding the ParentingInSceneObjects scene to the scenes in build list as well.
This also verifies an in-scene placed NetworkObject parented under a GameObject will preserve that hierarchy.
NetworkTransformStateTest:
Updated the bool parameters to be more meaningful named enums so you know what exactly is being tested.
Added additional NetworkTansformState.IsTeleportingNextFrame logic to the existing test.
Added an additional "step" which verifies the NetworkTransformState is additively collapsing for each detected axial delta over the relative threshold value.
Co-authored-by: Jesse Olmer <jesseo@unity3d.com>
Co-authored-by: Unity Netcode CI <74025435+netcode-ci-service@users.noreply.github.com>1 parent 41ef88b commit 64c4331
File tree
25 files changed
+3491
-266
lines changed- com.unity.netcode.gameobjects
- Components
- Runtime
- Core
- Messaging/Messages
- SceneManagement
- Spawning
- Tests/Runtime/NetworkTransform
- testproject
- Assets/Tests
- Manual
- InSceneObjectParentingTests
- Scripts
- Runtime/ObjectParenting
- ProjectSettings
25 files changed
+3491
-266
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
36 | 43 | | |
37 | 44 | | |
38 | 45 | | |
| |||
Lines changed: 21 additions & 46 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
451 | 451 | | |
452 | 452 | | |
453 | 453 | | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | 454 | | |
468 | 455 | | |
469 | 456 | | |
| |||
488 | 475 | | |
489 | 476 | | |
490 | 477 | | |
| 478 | + | |
| 479 | + | |
491 | 480 | | |
492 | 481 | | |
493 | 482 | | |
494 | | - | |
| 483 | + | |
495 | 484 | | |
496 | 485 | | |
497 | 486 | | |
498 | | - | |
| 487 | + | |
499 | 488 | | |
500 | 489 | | |
501 | 490 | | |
| |||
521 | 510 | | |
522 | 511 | | |
523 | 512 | | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
524 | 516 | | |
525 | 517 | | |
526 | 518 | | |
527 | | - | |
528 | | - | |
529 | | - | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | 519 | | |
544 | 520 | | |
545 | 521 | | |
546 | 522 | | |
| 523 | + | |
547 | 524 | | |
548 | 525 | | |
549 | 526 | | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
555 | 531 | | |
556 | 532 | | |
557 | 533 | | |
| |||
602 | 578 | | |
603 | 579 | | |
604 | 580 | | |
605 | | - | |
| 581 | + | |
606 | 582 | | |
607 | 583 | | |
608 | 584 | | |
609 | 585 | | |
610 | 586 | | |
611 | 587 | | |
612 | | - | |
| 588 | + | |
613 | 589 | | |
614 | 590 | | |
615 | 591 | | |
616 | 592 | | |
617 | 593 | | |
618 | 594 | | |
619 | | - | |
| 595 | + | |
620 | 596 | | |
621 | 597 | | |
622 | 598 | | |
623 | 599 | | |
624 | 600 | | |
625 | 601 | | |
626 | | - | |
| 602 | + | |
627 | 603 | | |
628 | 604 | | |
629 | 605 | | |
630 | 606 | | |
631 | 607 | | |
632 | 608 | | |
633 | | - | |
| 609 | + | |
634 | 610 | | |
635 | 611 | | |
636 | 612 | | |
637 | 613 | | |
638 | 614 | | |
639 | 615 | | |
640 | | - | |
| 616 | + | |
641 | 617 | | |
642 | 618 | | |
643 | 619 | | |
644 | 620 | | |
645 | 621 | | |
646 | 622 | | |
647 | | - | |
| 623 | + | |
648 | 624 | | |
649 | 625 | | |
650 | 626 | | |
651 | 627 | | |
652 | 628 | | |
653 | 629 | | |
654 | | - | |
| 630 | + | |
655 | 631 | | |
656 | 632 | | |
657 | 633 | | |
658 | 634 | | |
659 | 635 | | |
660 | 636 | | |
661 | | - | |
| 637 | + | |
662 | 638 | | |
663 | 639 | | |
664 | 640 | | |
| |||
1007 | 983 | | |
1008 | 984 | | |
1009 | 985 | | |
1010 | | - | |
1011 | 986 | | |
1012 | 987 | | |
1013 | 988 | | |
| |||
Lines changed: 25 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2070 | 2070 | | |
2071 | 2071 | | |
2072 | 2072 | | |
2073 | | - | |
2074 | | - | |
2075 | | - | |
2076 | | - | |
2077 | | - | |
2078 | | - | |
2079 | | - | |
2080 | | - | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
2081 | 2098 | | |
2082 | 2099 | | |
2083 | 2100 | | |
| |||
0 commit comments