Search Unity

Steps Through Conversion Of Existing Projects

Discussion in 'Entity Component System' started by ippdev, Jan 27, 2020.

  1. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    I think the paradigm I would like to get started with is to simply make all projectile rigidbodies a part of the ECS-DOTS system with Unity or Unity/Havok physics. I would want to leave the rest of my levels and particularly the gyrocyle vehicle alone. It has a bunch of code that looks like is not in the Unity math library you use with DOTS. All that helper stuff with Vector3 and Quaternions that us less than pure math heads have a tough time with. If you asked me to project a Vector onto another Vector without those helpers i would be lost until the damned vehicle reacted properly to the change I made. I understand that I have to tag the MeshColliders of the environment so the ECS subatomic species..Proton, Neutron, Electron etc can bang around the environment. However I am stuck on this and it is why I haven't begun the first line of code till I know what exactly I should be doing. If I use the rigidbody collider system on the vehicle to perform pickups on the atomic species what would be the trick there? The atomic species would be DOTS and I could fling thousands of them around. Awesome sauce! They can bounce off ECS injected gameObject to Entity mesh colliders, but from the troubles i have seen with hierarchical characters i haven't the heart to endure that after two weeks of 15 seconds play.crash to desktop..file bug report..confirm in the webs others experience the same and recycle back to play and crash after 15 seconds of emitted rigidbody projectile action.

    I have half of this set up as DOD design with lots of data only components that give values and parameters that are then used by behaviour scripts which do stuff. There are 183 AtomicCompositeProfiles of Elements and Isotopes with all relevant data about that atom as ScriptableObjects. There are 13 AtomicSpecies profiles as Scriptable objects for protons neutrons, electrons. An AtomAssembler that reads the profile fed it and assembles that atom. I want the subatomic species to run ender ECS-DOTS Unity/Havok physics and only add components to the standard game object for them to participate in that physics. I will add to my thread my experience and question as I move forward but need a few tips. I can imagine many other want to turn their ammo systems into ECS and not have to retool everything so..

    @MelvMay
    To start with..which packages do I need to load? [considering the above]

    I see both a Unity.Physics and Havok Physics. They work together from the docs..But.do I need both or is Unity physics good enough to fling rigidbodies around and register collisions. Seems it should be.. What extra advantage is gained from using both Unity and Havok physics together?

    I probably need the Mathematics, DOTS Editor and Entities Package along with Unity.Physics mentioned above (and Havok). Do I have to use the Hybrid Renderer. I do not want to. My graphics look like I want them currently and playing with various render pipelines beyond the legacy one has caused me pain I do not want to revisit.

    So..again. I want my first steps to be simple, so I am wanting to convert the subatomic species..represented by textured sphere single object rigidbodies with sphere colliders to work wth a DOTS physics system and have them collide with the environment and gyrocycle colliders..of which there are four..three capsule colliders and a mesh collider that is just a big flattened cylinder. And then start spawning them..what is the equivalent to rigibody.AddRelativeForce(Vector3.forward *impulseVelocity, ForceMode.Impulse);? ..and hope i don't crash to desktop.
     
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I would start by implementing the core problem, the physics simulation, in Unity.Physics. Try to do it in isolation just to see if it the core of what you need it can do what you want. Also see the Unity.Physics sub thread that's where all the Unity.Physics specific posts are now.


    IMO for your case I would probably suggest using some lower level api's and not the entity conversion stuff. The latter will be more work for an existing project. You want the most reuse for what you have and the least amount of change.

    You already have scriptable objects. If they are all separate SO's you probably want to turn them into structs. Then say just use a single SO as a container for all of them. So you still get editor support but the data itself is DOTS friendly.

    For entity creation I suggest just using the batch api's for entity creation. Very fast to instantiate lots of entities which you have, and fairly straight forward implementation.

    Rendering really depends on what you have now. Like if you were just using transforms vs instanced indirect and if you are using SRP or built in. Hybrid renderer is not a requirement.

    I would not shy away from using Mathematics, because there are equivalents posted for pretty much everything. You might have to search a bit as the info is scattered over multiple posts but it's all there. Avoiding this can in several ways come back to bite you later.

    Be prepared for a learning curve. Hybrid systems actually require the most knowledge of the fundamentals to do well. Because a lot of the best and least impactful solutions are inherently lower level, or at a minimum require a decent understanding of ECS and how the dependency and safety systems work. With Unity.Physics this is especially true as everything about it is fairly low level.
     
    ippdev and NotaNaN like this.
  3. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    Thanks @snacktime . That is enough pertinent data for me to take a run at it fresh in the morning. I will report back here when I figured some stuff out. I am pretty sure I can get the physics sim going and banging off the environment. The big what if for me is how to get the vehicle to collide with the Unity.Physics rigidbodies. I guess I could have a copy of the collider system and have it follow the transform of the gyrocycle..but should I or is there another method to make Unity.Physics and Physx object be aware of each other?..