#Help transitioning from 0.51 to 1.0. BuildPhysicsWorld.

1 messages · Page 1 of 1 (latest)

forest falcon
#

Hi! Can anyone tell me how to get the BuildPhysicsWorld to access the Collision World in order to make an OverlapSphere function for entities?
Added 2 pictures with the code that worked just fine in 0.51 and the new Console error after upgrading to 1.0.

odd canopy
#

tldr that stuff is on a singleton now in order to enable access from bursted isystems if desired

forest falcon
#

Thank you! I’ll check it out UnityChanThumbsUp

forest falcon
#

@odd canopy I just tried to use SystemAPI but unfortunately I can't use this in a Monobehaviour. Is there a way to do it outside a SystemBase?

odd canopy
#

no, systemapi doens't work outside a SystemBase or ISystem; you can use entitymanager though

forest falcon
#

And how can I use EntityManager to get the PhysicsWorldSingleton then?

#

@odd canopy I'm trying to use it entitymanager by using CreateSingleton and entityManager.World.GetExistingSystemManaged but I can't make it work

odd canopy
#

what are you trying to do overall? in general, i wouldn't think trying to talk to entities this much from a monobehaviour would be the best plan

forest falcon
#

I'm just trying to get the CollisionWorld in order to be able to do a OverlapSphere function in order to detect collisions. And I did this in 0.51 without an issue. I want to do it inside a monobehaviour because that's where I do most of the logic of what I want to do.

odd canopy
#

have you tried entitymanager.GetSingleton?

#

and have you established that this code is running after the code that creates the physics world singleton? in a system, this is easy to do with RequireForUpdate<PhysicsWorldSingleton>, but in a monobehaviour it's trickier

forest falcon
#

entitymanager.GetSingleton() doesn't exist in the list of options apparently

odd canopy
#

ehm

#

TIL

#

@runic drum how do you get a singleton from outside a system

#

i guess you have to manually GetEntityQuery and then assert that there's only one thing in it

forest falcon
#

How do I do GetEntityQuery?

#

I can only create it with EntityManager

#

Or did you mean create?

odd canopy
#

yeah create, but it caches it so it's secretly getorcreate

#

this api surface is so annoying

forest falcon
#

Sry for making so many questions but what do I exactly put in CreateEntityQuery?

#

PhysicsWorldSingleton?

odd canopy
#

yeah

#

ComponentType<PhysicsWorldSingleton>()

forest falcon
#

Ok but I'm kinda confused

#

I'm trying this:

#

EntityQuery PWS = entityManager.CreateEntityQuery<PhysicsWorldSingleton>();

#

And it throws an error

odd canopy
#

what's the erorr?

#

er hold on

#

that doesn't look right

forest falcon
#

Should it be like this?:

#

EntityQuery PWS = entityManager.CreateEntityQuery(ComponentType<PhysicsWorldSingleton>());

odd canopy
#

yes

forest falcon
#

It throws me this error:

#

error CS0308: The non-generic type 'ComponentType' cannot be used with type arguments

odd canopy
#

sorry i forgot everything

#

EntityQuery PWS = entityManager.CreateEntityQuery(ComponentType.ReadWrite<PhysicsWorldSingleton>());

forest falcon
#

Now it works!

#

Sry how do I access the Singleton now? 🤣

#

GetSingleton()?

odd canopy
#

yes

#

with <PhysicsWorldSingleton>

forest falcon
#

Nice thank you very much!!

#

You're awesome

runic drum
#

Keep in mind, you should remember to dipose queries yourself created with entityManager.CreateEntityQuery. So ideally use EntityQuery PWS = new EntityQueryBuilder(Allocator.Temp).WithAll<PhysicsWorldSingleton>().Build(entityManager); instead. EntityQueries created with EntityQueryBuilder is automatically disposed. For .Build(EntityManager) disposal happens on world destruction.