I’m having this problem for a little while where what happens in build is different from what happens in playmode, inside Unity.
Basically, I have the main character that is a prefab which is spawned from a PlayerSpawner entity.
When it gets spawned in playmode, everything is fine, player touches the ground, it moves and everything is fine. The real problem is when I build my project. The only thing that doesn’t work is the player, cause it no more collides with floor anymore. I don’t know what’s happening:eyes:
The first screenshot is inside Unity and the second one is inside the build of the project.
Did you enter play mode with a closed subscene? In case you don’t know, a closed subscene is what you have after build. Closed subscene = fully baked ECS data. So you have to make sure that this problem can’t be reproduce in the editor with a closed subscene when enter play mode.
Many ECS games have been successfully delivered for a while. So this can’t be a build problem.
Now that you mention it, I finally realised what was wrong with the subscene. Just need to ask another thing: How can I have a open Subscene in build? Is there some coding that needs to be done or is it some setting in the editor?
You can’t. The source Scene that provides the authoring data is not included in the build, only the entity-baked representation of the objects is included as a serialized subscene. There are some exceptions for specific supported companion components that will be carried over, and you can always attach assets / prefabs to entities by way of managed references in class components or UnityObjectRef / weak asset references in unmanaged and class components, but besides that you’re not going to have access to stuff from the original authoring scene. Remember, the Scene linked to a SubScene component in a parent scene is only for authoring data that gets converted by baking, it has no role in the running game. The only reason an “open” / “closed” subscene concept exists in the editor is because it lets you open specific parts of the scene hierarchy at a given time and make edits to them in both edit and play modes, while having the lightweight baked entity data for the other closed subscenes loaded at the same time.
Oook, I probably understood what you said. Do only Entities can interact with a closed SubScene? Cause it may be a problem for my player, since I stated it as a GameObject and not as Entity on the IComponentData. That’s the only thing I can think of my Player not being able to interact with the floor, which is in the SubScene.
To be precise, entities aren’t doing the interacting. Systems and code external to the World (like MonoBehaviours) create interactions. You can do a lot in code and create interactions between basically anything you want, but the natural state of things is that stuff like physics in an entities World are completely independent of anything outside it. I expect that your issue with the player is all to do with the fact that PhysX components (MeshCollider, BoxCollider, Rigidbody, etc.) stick around while the subscene is open in the editor (the simulation gets paused, so I’m guessing you’re manually moving your character around or something like that), and PhysX components in the subscene are no longer loaded when the subscene is closed (the underlying authoring Scene corresponding to it is closed). You’ll need to redesign your application in some manner. If you can bear to do it, you could rewrite your character to be an entity composed of Entities components (IComponentData) and driven by Entities systems (ISystem/SystemBase). Alternatively, it would be possible to inject a Unity Physics (ECS) collider into the world that corresponds to the GameObject character and acts as a proxy for physics simulation, but you would need to sync the transform / velocity data back and forth as needed, and is probably a considerable hassle as well.
It seems to me you haven’t understood how ECS works. It’s entirely different from they way of GameObject/OOP. I suggest you read the article DOTS Best Practices and the document of Entities package.
https://learn.unity.com/course/dots-best-practices
https://docs.unity3d.com/Packages/com.unity.entities@1.2/manual/concepts-intro.html