#[edit] Trying to load subscenes in a build with Content Management
1 messages · Page 1 of 1 (latest)
(and to be able to actually push it into servers, some stores having a strict limitation for patches sizes)
If I try to call
sceneData.ValueRO.scene.LoadAsync(new Unity.Loading.ContentSceneParameters()
{
loadSceneMode = UnityEngine.SceneManagement.LoadSceneMode.Additive
});
The loaded scene doesn't seem to have its content baked
So I'm trying to do something with SceneSystem.LoadSceneAsync but this one requires a EntitySceneReference which should be constructed with an already loaded SceneAsset
So: how can we load a WeakObjectSceneReference without actually loading it into the scene/world just to have a reference we may give EntitySceneReference so we can properly load it ?
Yeah.. I don't think it would work, but I don't know ^^'
WeakObjectSceneReference is a normal scene reference
you can only load game object with it
for entities you must use EntitySceneReference
or as alternative - you can ensure it's inside the build otherwise
and load via guid
can EntitySceneReference be loaded from a file that's outside the build ?
and what is the subscene section index ?
no, you just load subscene directly
subscene can be split on sections
can be useful for unloading interiors and etc
so I guess 0 would be the default
yeah, by default it's just 1 section
Is what I'm trying to achieve possible ?
I mean: having scenes / entities using authoring/baker loaded from a content management system (which would be built apart from the rest of the build, like the addressables)
yes, there is a page in manual about it
https://docs.unity3d.com/Packages/com.unity.entities@1.0/manual/content-management-load-a-scene.html
^ Is exactly what doesn't work, in my case
this is about loading game object scene
that is within build
Yeah, but we are talking about baked scenes that produces entities
I'll try the script tomorrow, though, to see
delivering content is about any content
You said "this is about loading game object scene", so I thought you meant scenes that has gameObjects (and no entities)
yes
this is what your link is about
oh
okay
yeah, indeed, I though you were talking about your link; I'm getting tired (end of the day ^^')
remoteUrlRoot is probably the path to the local content, but what is initialContentSet ?
oh there's this on the forums: https://forum.unity.com/threads/where-can-i-find-samples-for-contentdeliveryservice.1437958/
alright, let's try this
This doesn't explain how a content-managed entity-(sub)scene is to be loaded.
The script doesn't work on editor, but 'works' on build, 'works' as "goes to the next scene".
I continue digging :p
Oh, just studied the ContentUpdateMenuItem, I can add disabled scenes
I have something that works in the editor but not in build
Scene 0: Has an empty scene with a script that does like in the docs:
#if ENABLE_CONTENT_DELIVERY && !UNITY_EDITOR
ContentDeliveryGlobalState.Initialize(remoteUrlRoot.Replace('\\', '/'), Application.persistentDataPath + "/content-cache", initialContentSet, s =>
{
if (s >= ContentDeliveryGlobalState.ContentUpdateState.ContentReady)
LoadMainScene();
});
#else
LoadMainScene();
#endif
This loads the next scene
In the next scene, I have a simple subscene with the 'other-subscene-loader'
That has an authority with an array of EntitySceneReference, creating as many entities with a component containing a scene ref each
public class SpawnersCreatorAuthoring : MonoBehaviour
{
public EntitySceneReference[] scenesGuid;
class SceneRefSampleBaker : Baker<SpawnersCreatorAuthoring>
{
public override void Bake(SpawnersCreatorAuthoring authoring)
{
//var entity = GetEntity(TransformUsageFlags.Dynamic);
foreach (EntitySceneReference sceneRef in authoring.scenesGuid)
{
var sceneEntity = this.CreateAdditionalEntity(TransformUsageFlags.None);
AddComponent(sceneEntity, new SpawnersCreatorComponent
{
sceneRef = sceneRef
});
}
}
}
}
Then the system loads them:
public void OnUpdate(ref SystemState state)
{
foreach (var sceneData in SystemAPI.Query<RefRW<SpawnersCreatorComponent>>())
{
if (sceneData.ValueRO.startedLoad == false)
{
SceneSystem.LoadSceneAsync(state.WorldUnmanaged, sceneData.ValueRO.sceneRef, new SceneSystem.LoadParameters
{
Flags = SceneLoadFlags.NewInstance
});
sceneData.ValueRW.startedLoad = true;
}
}
}
I'll add a cube and a sphere to know what's loaded / not loaded
oh.. even the first subscene hasn't been loaded o.O
should have added those primitives earlier >.<'
no error in logs
Actually, can't we create entities from monobehaviour without using Baking ? I just need an entry point, a "main()" ^^'
only if you manually create it from scratch
basically recreation of baking
Yup, I did this, build in progress 🙂
public class LoadSubScene : MonoBehaviour
{
[SerializeField] private EntitySceneReference[] scenesGuid;
void Start()
{
EntityManager manager = World.DefaultGameObjectInjectionWorld.EntityManager;
foreach (EntitySceneReference sceneRef in scenesGuid)
{
Entity e = manager.CreateEntity(new ComponentType(typeof(SpawnersCreatorComponent)));
manager.SetComponentData(e, new SpawnersCreatorComponent {
sceneRef = sceneRef
});
}
}
}
I deleted the authoring that was basically doing this job before
:/ now I have a black screen
.....and a crisis on another project; I must pause this :/
I'll try later 🙂
don't
you'll have to recreate thousands lines of code
and if you need physics or graphics...
oh well
this is like the biggest black box of entities packages
even with all source code available, trying to understand it might kill people 🤣
I have some "Doliprane" right next to me, I'm fully prepared xD
(estimation of death: a week)
just remember, that unity has 3k developpers
and you're only one
(i think)
yeah this will be a complicated war xD
but I'm not alone, we are two (in my company).. erm.. well okay, we can't win xD
anyways
just figure how content management works over web
and you're suited
I also would love to know how it works tbh
another guy on a forum just posted this:
private IEnumerator LoadSubScene()
{
yield return null;
var world = World.DefaultGameObjectInjectionWorld.Unmanaged;
var meta = SceneSystem.LoadSceneAsync(world, subScene.SceneGUID, new SceneSystem.LoadParameters {Flags = SceneLoadFlags.NewInstance});
while (!SceneSystem.IsSceneLoaded(world, meta))
{
yield return null;
}
}
so I'll retry the authoring approach, didn't know SceneSystem could be called from a MonoBehaviour x)
but.. this is weird: it worked in the editor, so maybe it's just that the content wasn't actually loaded
so I'm pretty sure I'll get the same result
Weird, I have black screens now even if I remove my scripts (from the scenes).. something killed the project somehow.. I'll remove the Library folder I guess
STATE => NoContentAvailable
maybe this comes from the fact that I don't have anymore subscene in a scene in the project :/
you absolutely shouldn't
Alright, so removing Library + Adding an empty subscene removes the black screen.
Haven't tested the last test I mentioned (trusting you)
I get some logs :
Loading E:/Projects/(...)/TestDots/ContentBuild-RemoteContent
STATE => DownloadingCatalogInfo
STATE => UsingContentFromStreamingAssets
Loading main scene
Unloading 6 Unused Serialized files (Serialized files now loaded: 0)
UnloadTime: 0.214600 ms
Unloading 4 unused Assets to reduce memory usage. Loaded Objects now: 1829.
Total: 1.596500 ms (FindLiveObjects: 0.088900 ms CreateObjectMapping: 0.032800 ms MarkObjects: 1.461700 ms DeleteObjects: 0.013000 ms)
Could not open file E:/Projects/(...)/TestDots/Builds/TestDots_Data/StreamingAssets/EntityScenes/d7b4c21b291cb9c4e9ac6f486d41a748.entityheader for read
Loading Entity Scene failed because the entity header file couldn't be resolved: guid=d7b4c21b291cb9c4e9ac6f486d41a748.```
So.. it's trying to load things from StreamingAssets.... which is empty
so, I'll try to populate it
..Actually, the StreamingAssets is automatically populated when building
..but it seems it only contains what was setted as subscenes in builded scenes.
Which would mean I need a scene referencing every subscene I wish to build
The black screen occured because I had no folder generated when no subscene was added in any scene (my first scene is black (no camera))
_
Alright.. every thing seems to be setted, but my subscene isn't loaded
Maybe because I need the scene I want to load my scene to have an empty subscene too?
Nope..
Not even my empty subscene that has its reference in the mainscene is loaded..
(in build)
even though it works on editor
in editor it always converts on the go from asset database
any subscene referenced in normal scene
or baked via EntitySceneReference (which gets included in subscene above) will be included
Loading Entity Scene failed because the entity header file couldn't be resolved: guid=d7b4c21b291cb9c4e9ac6f486d41a748.```
^ This error doesn't pop anymore, but nothing happen
This one is false
Is it possible to add new files to StreamingAssets in runtime?
works for everyone else
When I just reference a scene by using an EntitySceneReference, then the scene isn't created in the StreamingAssets on build
how do you reference it even
it must be part of subscene that gets included already
anyways, after you build your content bundle you probably have a baked subscene assets somewhere
I think this needs to be sent somehow
and what I'm not sure about - how Unity loads it into streaming assets
I don't know why when I build RemoteContent, it still uses StreamingAssets ?
I suppose this is indended?
So I have
- RemoteContent (in local file system)
- Load it in cache in Persistant Data path
- But actually use something in StreamingAssets
What was weird is that even so I created a catalog myself by using the scenes I wanted, it was as if it didn't care about it.
It was still trying to access the StreamingAssets content made by building
I have the ENABLE_CONTENT_DELIVERY define symbol
_
Maybe, it has in StreamingAssets the initial wanted catalog. if an update is required, downloads it in cache then overwrite the streaming assets (that would make sense)
but since my remote catalog is supposed to be different...
_
In the docs they use RemoteContentCatalogBuildUtility.BuildContent but I see with intellisense that there is a ContentArchivesBuildUtility.BuildContentArchives
I'll look into that
[edit] Trying to load subscenes in a build
[edit] Trying to load subscenes in a build with Content Management
maybe a phrased it weirdly; I didn't mean to call it from an authoring monobehaviour - but - to have a classic monobehaviour calling a subscene through SceneSystem; subscene that would call the other subscenes as I wanted
well.. same result..
yep, that's exactly what I am advising against
injection of monob into ECS worlds is awful
This script worked (logs are pointing to that) but it's the loadScene within the system that doesn't work
This isn't what I do though ?
that's exactly what code above is about
It's just loading an ECS scene from a GameObject scene (as 'NewInstance', which I believe is to make a subscene) ?
using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using Unity.Entities.Serialization;
using Unity.Scenes;
using UnityEngine;
[WorldSystemFilter(WorldSystemFilterFlags.Default | WorldSystemFilterFlags.Editor)]
[UpdateInGroup(typeof(PresentationSystemGroup))]
public partial struct SpawnersCreatorSystem : ISystem
{
public void OnCreate(ref SystemState state) { }
public void OnUpdate(ref SystemState state)
{
foreach (var sceneData in SystemAPI.Query<RefRW<SpawnersCreatorComponent>>())
{
Debug.Log("SpawnersCreatorSystem - detected sceneData");
if (sceneData.ValueRO.startedLoad == false)
{
Debug.Log("SpawnersCreatorSystem starts load");
sceneData.ValueRW.loaderEntity = SceneSystem.LoadSceneAsync(state.WorldUnmanaged, sceneData.ValueRO.sceneRef, new SceneSystem.LoadParameters
{
Flags = SceneLoadFlags.NewInstance
});
sceneData.ValueRW.startedLoad = true;
}
else
{
var loadState = SceneSystem.GetSceneStreamingState(state.WorldUnmanaged, sceneData.ValueRO.loaderEntity);
Debug.Log(loadState);
sceneData.ValueRW.loadState = loadState;
}
}
}
public void OnDestroy(ref SystemState state) { }
}
I believe this script does the same thing ?
Let's try to create a World instead of trying to get one
I edited the script to get an idea of the loading state.
I get "Loading" every frame
this runs from within world loop
mono behaviour runs in different loop
technically it's not a problem
for prototyping and testing
but when you start creating actual logic by injecting into default world
you are dooming yourself
😅
no?
you just create your logic from within systems
not monobehaviours
or other logic entry points
That's the point: how can you have an ECS entry point if you can't load ECS logic ?
there is a bootstrap entry point
it creates world
either default, or you override with your own
everything else is from within systems
maybe with one exception - subscenes. They also inject into world
The last script I sent is supposed to load an ECS scene (subscene) from an ECS world, am I right ?
yeah, past the point of bootstrap - everything can be done in ECS world
So gameobjects have nothing to do with it ?
as well as bursted
nope
nope, gameobjects have nothing to do with it
or nope, gameobjects do have something to do with it ?
[^ compiler-like-brain-guy-here xD]
game object have nothing to do with entities
if you want to use game objects - you use them from within systems
not other way around
Oh, I understand what you mean.
Can you have UI, Input, Network, Audio in ECS ?
there is netcode for entities specifically
everything else you just use from within systems normally or via hybrid
I thought of having 'shadowed' components for the Hero (for example), a character with no renderer that's placed where the gameobject (which have renderers) is actually placed so that swarm-like-units (baked content) may attack him and avoid him.
Since my hero is unique and don't need to be an entity.
It actually work (in editor): what needs to be placed in ECS world is in ECS world concerning the hero, but the input intent is setted by monobehaviour and a system comes to set the value within a component so that other systems may work with it.
if you want to have ECS - you have everything in ECS
I don't understand why, though ?
how are you going to sync game objects with entities then?
entity physics have nothing to do with game object physics
it would be as if you are trying to synchronize two different games with each other
that doesn't matter
target detection, anything
either you use ECS for everything, or you use ECS as particle system, nothing more
as I said, The unique units (a boss or the hero) will have it's data queried from an entity then, everything is entity handled
yes, it feels as doing network within the game; exactly the same as when playing with native code sometimes.
but that's not a big issue, we just need to avoid having a lot of transactions points
👴
and for each transaction point you'll have tons of bolierplate
while you can have non if everything is entity
it's one or two per frame max (made by me*)
for now, I'm in a kind of R&D phase
we are not sure to use ECS yet
but I thought it would be a good idea if we have tons of units
ECS is generally better than OOP for simulation type of games
architecture makes it so much easier to work with
especially if your project doesn't have stricktly defined specifications
so knowing the limits is the point, and if we should have the whole game in ECS, knowing that we must prepare for multi platform and so on..
having OOP is not really an option to us
If what you say is true, then we should abandon ECS.
I'm a little optimistic and want to try a little prototype before reaching a conclusion
not our case, really x)
since we have presented the project to people to get funds ^^
(funds for a prototype / proof of concept)
that's not what I meant
I thought of using a struct to group everything the entity might need, so that only a single transaction point would be needed
I mean if you don't know exactly how your project codebase should look to handle all edge cases - OOP code can be really tricky
here's example:
- Fantasy game. Designer asked to make weapons: ice sword, fire sword.
- Developper made a design:
Weaponabstract class.Swordinherits.FireSwordandIceSwordclasses inheirit. - Then designer asked for Fire and Ice Sword simultaniously.
- Developper had to rework his system/Duplicate fire/ice logic.
depends, at your example, I'm not sure I will do the Fire/Ice sword classes
depends on what they do. If they induce an effect, I would do an EffectInducingWeapon or maybe an array of WeaponEffects
this is a silly example
but I think many OOP developpers have encountered similiar case in their career
yeah, I know, but I think having to duplicate code is very rare
Personnaly I prefer to rewire things a little bit
you can emulate inheritance by having components that don't exist without their base
CharacterComponent
UniqueCharacterComponent
HeroComponent
yes, that's correct
unless I don't understand your example correctly
I think you were saying all this to state that the parodigms are so different we shouldn't use them in parallel.
In that regards, I disagree, we can adapt so that the classes that are supposed to communicate reflect each other well and have their own jurisdiction.
For example, if health is managed by ECS, no damage should occur outside ECS world.
Or if movement is managed by ECS, then all movement should occur within ECS. But some parameters (wantedDirection, wantedOrientation) for this movement can be queried from gameObjects if the unit is unique.
not really. it's about intersection of paradigms. All UI code I have is pure OOP within ECS project. but it's fully isolated into it's own assemblies and aside from one public interface, ECS doesn't know anything about UI
but then if you try to have UI code modify ECS world via callbacks... oh well
good luck debugging and refactoring that, once you have a big codebase
No, that won't happen.
I see that as two ships at see looking at each other with a telescope x)
you mentioned having hero as GO, though
and if one or two frames are inexact, that shouldn't pose problem
assuming units are entities
hero is GO, have some of its logic in ECS, and it's brain "intents" in Go
yeah, that sounds awful
Pratical example: if we build a game for Switch. Switch asks us to use its OOP classes (mandatory).
In that case, should ECS be complely ignored?
for example; a pause menu should pause everything, ECS systems too
I worked on quest 2 project, which also has some very specific VR API, but it's realtion to game logic is 0, because it's literally just about passing input/rendering stuff
just have a system that manages pause?
input is quite related to gameplay since it's a part of gameplay parameters
yeah, that's basically what I meant by brain intents
In my case: in which direction should my hero go
In your case: where should my hands/head be, which buttons are pushed
all of this is just a struct with values though
input system reads it before simulation
and then other systems access it via component
no, no, I won't do callbacks
and only ECS knows GO, not the other way around
so that it writes/read data (without calling anything)
well, ECS is fine calling something
Then, there will be callbacks in OOP but that won't be called from ECS, only from the update of the Go when it will check the data
OOP calling ECS is not
yup, I saw that 😄
yeah, I see what you mean - it's partially forced on us, for using stuff like particle systems
as we rely on it's own update
but in general, my opinion is that absolutely all source of logic should be from within systems
because this way you have absolute control over execution order
and you can put any specific logic to update between any data flow you need
while with monob updates - you are forced to update before simulation
and after initialization group
besides
monob updates are slower
due to native->managed->native interop
My Swarm-like-units are completely handled in ECS: there no question about it
The only data that may be passed is some counters (such as the remaining units count)
so having slow gameobject is fine since there won't be a lot of them
(ui, camera, hero, boss, buildings (visuals) + ui 'plugins')
__
But to even try doing that I must manage to have a bootstrap xD
which at this time doesn't work yet xD
ok bootstrap being an ECS concept, this was wrongly phrased
I want my ECS baked content to be loaded in the ECS world x)
it's not about performance, it's about you having to duplicate logic
your swarm like units have hp, right? Your boss doesn't?
your units move. your boss doesn't?
complicated animations can be a reason
yeah, rukhanka
no
it's pure ecs
I talk about hybrid
when your entity contains reference to skinned mesh go prefab
system manages it's instantiation
and passing entity component data to animator parameters
as well as transform
different systems do that in fact
as wlel as disposal of go when entity is destroyed
one way interaction ECS -> GO
For now I thought of having units are two separated elements is basically because things might be asked, which I don't know of yet.
I could have a scenario of events (currently managed by OOP) that asks a boss to do some things
x)
Moreover programming in ECS is quite difficult, the R&D I'm doing actually proves it: I can't do a thing I do in 2s in OOP : loading a scene.
I had previously issues to spawn a unit, and everything we must do in ECS must be redone often (well.. we take plugins, but ^^)
so having a part of OOP programming is confortable
What MUST be done in ECS will be done in ECS, as for the rest.. I prefer staying where I know things (for me and the whole team)
because, we keep getting stuck otherwise, and as you said: deadlines
If being ready to be productive in ECS was faster, this would have been a no brainer I guess
but even hybrid animations were giving weird results : the rig have additional development constraints otherwise some skinned mesh just don't work, that means graphists must be extra vigilant.
So I prefer them to be vigilant only for units they need to be vigilant
That's a matter of your knowledge and experience
hybrid equals game objects
Rukhanka != hybrid
That's just assembly name he used similiarly to how Unity named their baking assembly
Well, I use that on baked characters and it works
Hybrid is known as a way to have classic unity game object do something, while controlled by entities
so for example: instantiating particle systems GO prefabs from within entities
or having game object animations for skinned meshes
the way I see it : it's a wrapper so that their pure ECS can work with baked gameobjects
no
game objects are just authoring data
sorry baked entities (from go authoring)
in baking all it's data read to create unmanaged animation data
after you build your project - there won't be anything left of authoring game object
yeah, I understood that
hybrid is different; it's using game objects in runtime
it bakes game object prefab isntead of unmanaged data
oh ?
and then instantiates game object and controls it
I thought Hybrid == using Baker+Authoring
public class MyHybridPrefab : IComponentData { public GameObject prefab; }
Hybrid is a word used to describe hybrid between classic Unity (game objects) and DOTS (entities)
Managed components used to be called Hybrid components even
The chicken I have is a prefab.
This prefab is referenced by an authoring gameobject (using 'GetEntity' on the GameObject Prefab)
And then the chicken is spawned from a system, by using an ECB.
The prefab is what's containing what I shared. (#1154077489774202971 message)
Is that Hybrid or not at all ?
no
oh, but I'm not sure this is a runtime gameobject since it might have been baked when the authoring was
hybrid is when you bake a game object reference with VFXGraph
game object prefab*
and then isntantiate it in runtime using Object.Instantiate to playback VFX
but all that code is called from within entities systems
based on entity simulation
Okay, so Rukhanka called Hybrid what was just Authoring
Because ProjectDawn (agents navigation, local avoidance) did the same thing.
So Unity called Hybrid, the authoring baking assembly
Do unity also call hybrid what you call hybrid ? So that I won't lose myself in the docs ^^'
Records a command to add a hybrid component and set its value for all entities matching a query.
Haven't tested VFX Graph
Are you talking about this ?
https://unity.com/fr/visual-effect-graph
just an example. Hybrid is used for a lot of stuff which has no alternative in ECS
audio for example
do you have an example, or a source somewhere, I might be blind, I don't find :/
you create it yourself
Entities Graphics has it's own as well
if you try to bake Light
it will be baked as hybrid
so, it's literally going to be a game object hidden in hierarchy, fully managed by Entities.Graphics code
or SpriteRenderer
there are a bunch of hybrid they do
that's outdated tutorial
I'm on Unity 2022.3, entities package 1.0.11
"The Entities Graphics Package replaces the Hybrid Renderer Package." oh right
and this tutorial is for 0.51
I'll try compiling the samples.. and then tweak it to try to be on the same level
I'm getting nowhere right now :/
Something I'd suggest instead of forcing yourself into awful ECS practices - just don't use ECS
use bursted jobs
if don't want/don't have time to learn ECS - best to just avoid it alltogether, until such opportunity occurs
Simply using data oriented patterns within game objects + jobs and burst can achieve equally same or even better boosts than pseudo GO-authoritative hybrid
Moreover programming in ECS is quite difficult, the R&D I'm doing actually proves it: I can't do a thing I do in 2s in OOP
I can also say that about the time I learned OOP with a procedural programming mindset. It was hard to reason about object relationships and interactions. I think it's really just the matter of time and practicing. But as Issue said, if you don't have time, then avoid it altogether or you'll have a mess hard to fix later on.
It's more about the whole company than me.
If I can do it alone, then it's fine to take the time; but that means just a part of the project must be ECS. Not the whole program
__
I tried building the samples (Entities sample, the Streaming part), but it doesn't compile with 2022.3.6f1 :/
https://github.com/Unity-Technologies/EntityComponentSystemSamples
Do you know of a buildable sample for ECS Streaming I can test?
Everything seems to be done for Editor ^^'
Edit: deleted everything except for the folder "Streaming/RuntimeContentManagement" and "SceneDependencyCache" + "Settings"
a build can be done, and things are scrolling, now: it's study time 🙂
It's more because of the implementation than the paradigm ^^'
(We have to learn Unity all over again, the ECS API, and hit all the walls that may stand, such as.. how to load a scene at runtime (it works on editor))
ECS reasoning isn't that complicated
..this is weird.. in the samples, the subscenes seems to be loaded automatically.
this isn't what happens with my own project..
Nice! 🙂
So the sample doesn't work once we add the define symbol "ENABLE_CONTENT_DELIVERY"
Now I need to make it work again with the first scene
It doesn't work with the first load scene 🙂
So the issue comes from the define symbol, not the way I load scenes
_
I'll try to load the gameobject scene that contains the subscene through this:
Maybe that will work
even trying without subscene, with a SystemBase to load once the ContentDeliveryGlobalState.Initialize callbacks sets a singleton boolean..
can't load the first scene this way.. ..even in the sample
well. budget asks me to stop researching on that front. I'll need to develop other aspects of the prototype, I flagged a warning on the content management system on our end.
So I'll close the topic for now
-> I propose to continue the discussion here, if you want to answer to something.
https://forum.unity.com/threads/how-to-actually-use-enable_content_delivery-in-build.1495526/