LogoLogo
HomeOnline DashboardAPIDiscordForums
SDK 0.4.14
SDK 0.4.14
  • Welcome
  • Overview
    • What is coherence?
    • How does coherence work?
    • Features and Roadmap
    • Requirements
  • Get Started
    • Install coherence
    • Scene setup
    • Prefab setup
    • Build and run
    • Baking and code generation
    • Create a free account
    • Deploy and share
  • Authority and communication
    • How authority works
    • Authority transfer
    • Commands
    • Server-side and input queues
    • Animations
  • Persistence
    • Overview
    • Configuring persistence
    • Storage
    • Example – A global counter
  • Optimization
    • Overview
    • Simulation frequency
    • Areas of interest
    • World size
    • Level of detail
    • Interpolation
    • Extrapolation
  • Connected entities
    • Overview
    • Entity references
    • ConnectedEntity component
    • Parent-child relationships
  • Simulators
    • Overview
    • Client vs. simulator logic
    • Build and deploy
    • Simulator load balancing
  • Tutorial project
    • Get the Tutorial Project
    • Start Tutorial
      • 1. Transforms
      • 2. Physics
      • 3. Persistence
      • 4. Animation and Variables
      • 5. AI Navigation
      • 6. Network Commands
      • 7. Network Events
  • Game Services
    • Game account
    • Key-value store
    • Matchmaking
  • API reference
    • Network SDK
      • CoherenceSync
      • MonoBridge
      • LiveQuery
      • Archetype
      • Sample UI
      • Settings Window
    • Cloud API
      • API tokens and keys
      • Server discovery
      • Game account
      • Key-value store
      • Matchmaking
    • Replication Server
    • Simulation Server
    • Entity Component System
      • Network Entities and Components
  • Schema reference
    • Overview
    • Specification
    • Field Settings
    • Archetypes and LOD-ing
  • Resources
    • Downloads
    • Video Tutorials
    • Glossary
    • CLI Utilities
    • Helper Scripts
    • Troubleshooting
  • Community
    • Discord
  • Additional information
    • Pricing
    • SLA
    • Unreal Engine support
    • Peer-to-Peer (P2P)
    • Known Issues
    • Version History
Powered by GitBook
On this page
  • Query
  • Usage

Was this helpful?

Export as PDF
  1. Connected entities

ConnectedEntity component

Query

Objects with the ConnectedEntity component on them are treated in a special way by the query system. If the entity they are connected to is present in a query, then they are also included automatically. They are also excluded/removed automatically when the entity they are connected to goes out of the query.

This means that the entity will never show up on its own – it will always have to be part of a query where the connected entity is included.

Usage

You need to add the ConnectedEntity component to entity. The entity will disappear from all queries that don't have the entity this is connected to. The entity has to be converted to its SerializeEntityID before it can be used in the ConnectedEntity component. This can be done using the CoherenceMonoBridge.UnityObjectToEntityId static function.

var entity = coherenceSync.LinkedEntity;

if(entity != Entity.Null)
{
    var serializeId = CoherenceMonoBridge.UnityObjectToEntityId(other)
    EntityManager.AddComponentData(entity, 
        new ConnectedEntity 
        { 
            Value = serializeId
        }
    );
}     

Please note that the ConnectedEntity component is only available in from code in ECS at the moment. It will be fully integrated with the editor flow in the next release.

Last updated 3 years ago

Was this helpful?