When entities are synced to a RealityKit app from another peer, file-based resources are resolved based on what files have
already been loaded into the app receiving the entities.
This means that the client app must arrange to have already loaded necessary files by the time the multipeer connectivity session begins. This could mean that the entity loaded by your call to
Entity.load(named:in:) is already somewhere in the scene… but you probably don't want that, since that would mean that each peer is contributing another entity to the synchronized scene.
Instead, you can load files containing your resources and keep them referenced somewhere in your app's model or controller, without adding them to any ARView. That keeps them loaded, in preparation for an entity arriving via network sync.
One important detail is how these file-based resources are identified across peers. It's straightforward for files in your app's bundle, but for files in other locations on the file system (e.g. those loaded with
Entity.load(contentsOf:withName:)), the passed-in name can be used to ensure that the networked entities find the already-loaded resources when they sync over. If the file isn't necessarily present on every peer, your app will have to make arrangements to transfer the file itself.
sendResource(at:withName:toPeer:withCompletionHandler:) is a useful mechanism to accomplish that.
(Feedback about documentation, error messages, or the API is
most welcome!)