Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Get PhysicsWorldSingleton from MonoBehaviour

Discussion in 'Physics for ECS' started by monsterrungame, Feb 19, 2023.

  1. monsterrungame

    monsterrungame

    Joined:
    Sep 27, 2019
    Posts:
    15
    Guys how to get PhysicsWorldSingleton from MonoBehaviour? I'm trying to get it by SystemAPI:
    Code (CSharp):
    1. PhysicsWorldSingleton physicsWorldSingleton = SystemAPI.GetSingleton<PhysicsWorldSingleton>();
    but got error:
    InvalidOperationException: No suitable code replacement generated, this is either due to generators failing, or lack of support in your current context
     
  2. eggsamurai

    eggsamurai

    Joined:
    Oct 10, 2015
    Posts:
    99
  3. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    282
    SystemAPI is only intended to be used inside system callback methods (OnUpdate etc), hence the names.
    Use alternative API for singletons.
     
  4. eggsamurai

    eggsamurai

    Joined:
    Oct 10, 2015
    Posts:
    99
    any alternative API for singletons exists?
     
  5. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    282
    ... Read the second page I linked.
    In any event, you should try and look for something with a search engine before asking something so simple.
     
    eggsamurai likes this.
  6. yifanchu183

    yifanchu183

    Joined:
    Jul 4, 2019
    Posts:
    41
    use
    entityManager.CreateEntityQuery(typeof(PhysicsWorldSingleton))
    with EntityQuery.GetSingleton API