Our project relies quite heavily on Actor Attachment. However, we’ve noticed that the replication of Actor attachment seems to be very unreliable. We’ve noticed all of the following:
- Child Actors will attach to Parent Actors on the client, but visually still appear at the incorrect relative Transform even if the Details panel is correct (shown in the provided repro project).
- Child Actors will attach to Parent Actors on the client, but with an incorrect relative Transform both visually and according to the Details panel.
- Child Actors replicating a null AttachParent pointer to clients in OnRep_AttachmentReplication(), even though the Attach Parent exists both on the Server and Client, and the Child Actors are correctly attached to their Parent Actors on the Server.
I haven’t been able to reproduce all of these in the given repro project, and none happen 100% of the time for us, but they all occur frequently enough in our editor and in our builds that it is a big barrier to our game working properly. While we aren’t using the 5.5 version from the launcher, I’m confident in saying that our version is not modified in a way that would affect the basic attachment functionality of the engine.
In terms of the game loop, the Server usually starts by spawning a bunch of Parent and Child Actors. Child Actors are attached to Parent Actors in groups, and the Parent Actors may or may not have physics simulation enabled, which requires the Parent Actors to replicate their movement. Typical starting counts of Parent and Child Actors each range into the 100s, and grow over time as more Parent and Child Actors are spawned over the course of the game. Child Actors may also change their attachment over the course of the game to a new Parent Actor.
For Child Actors, we typically have a Mesh as their Root Component with physics simulation disabled. For Parent Actors, we typically have a Sphere Component with a radius of 0, just to allow it to have the physics state necessary to simulate its attached Child Actors as needed. The Actor classes in the provided repro project approximate the setup of our Actor classes.
Are there best practices or assumptions that we’re violating with Actor attachment that are causing us to see so many issues?
Hi,
The issue you’re seeing with the null AttachParent may be expected, provided that the correct AttachParent is eventually received on the client. It is possible for the child actor’s open bunch to arrive on the client before the parent’s, causing it to be spawned before the parent. However, once the parent is received and spawned, the attachment should be set up as expected.
As for the incorrect relative Transforms, this is also a known issue: https://issues.unrealengine.com/issue/UE-211486
For more info, including a potential workaround, you can check out this related thread: [Content removed]
There are unfortunately a number of known issues with child actors. This does make it difficult to recommend using them, especially at the scale you’re seeing in your project (for more info: https://dev.epicgames.com/community/learning/tutorials/l3E0/myth-busting-best-practices-in-unreal-engine#don%E2%80%99tusechildactorcomponent?)
Thanks,
Alex
Hey Alex,
Thanks for the reply. I should have clarified that (despite my bad terminology) we actually aren’t using Child Actor Components, since we’re aware of the issues related to them. We do still do a great deal of spawning Actors and then immediately attaching them though, so perhaps that’s why we’re running into similar issues? Regardless, I’ll take a look at the links you gave.
As for the null AttachParent, the problem we seem to be seeing is that the attachment is not being set up at any point, even when we can see that the appropriate Parent is spawned on both the Server and Clients (we verify that it’s spawned using a separate replicated ID system). Is there something that could be preventing that pointer from updating and setting up the attachment correctly?
Hi,
I see, I apologize for the misunderstanding!
There are unfortunately also a number of known issues with attachment replication, such as this one related to the “Keep World” scale rule: Unreal Engine Issues and Bug Tracker (UE\-172512)
There was also a reported issue where actors attached to physics actors could have the wrong location on clients joining a match in progress, but I don’t think that’s the case here.
After digging into your repro project some more, I did spot something that could cause problems. When a “child” actor is spawned, the parent actor pool is notified on both the client and server (in AAttachChild::BeginPlay). It’s possible that this is causing AAttachChild actors to be attached locally on the client, changing some values locally and causing transform issues when the authoritative attachment info is received from the server.
In my own testing, moving the NotifyAttachChildSpawned call to inside the HasAuthority check seemed to fix the issue.
As for the AttachParent issue, I’m not sure why the replicated pointer wouldn’t get mapped in that case. The NetDriver should keep track of unmapped object reference properties and update these to point to the correct object when it is available. You can enable and increase the verbosities of the LogNet, LogNetPackageMap, and LogNetCore categories to get more info in your logs on this.
Thanks,
Alex
Thanks Alex, at this point we’re having one of our engineers look at doing something custom for attachment replication, since we haven’t been able to iron out all of our issues. I’ll update this thread further with final details when we settle on something.