#AudioSource not playing from system
1 messages · Page 1 of 1 (latest)
Are you sure that state.EntityManager.HasComponent<AudioSource> returns true?
Pretti sure, log is logging
I doubt that AudioSource can work without GameObject
My AudioSource is on a GameObject which is then baked as Entity as part of a Prefab, what is the difference between doing this and simply put an audio source on a subscene as a component of a GameObject?
It should still make a companion GameObject with an AudioSource, right?
Mmm instead of adding the AudioSource component to the entity, try using a component with the UnityObjectRef<AudioSource> field
And create AudioSources in runtime
In new GameObjects
I doubt
Something like this is implemented only in Netcode for entities
Ok... What happens to child gameobjects of prefabs then?
Because something is happening here
Engine Audio source is just a GameObject with Audiosource
Can i see authorings?
AudioSource is added like managed component
yes, exactly what I was thinking
But why doesn't work then
Didn't you write your custom Baker for that?
I don't do Authoring for Audiosource, only on the CarShiftAudioModuleAuthoring which is the component under the Audiosource as you can see
Ok
CarAudioModule is a scriptableobject with settings
I have not heard of an official implementation of audio systems for entities.
I know, but, if the component is managed it should work, right?
No
For this you need system
Yea, i know
ok but why it works when on a single gameobject on a subscene then?
maybe because awake is called differently from update, and still works on entity world
in someway
Example:
This works even outside play mode
But it only works when AudioSource play on awake is checked
I think this is due to a feature of the entities in editor implementation.
So it shouldn't work in the build
Ok
@queen lagoon I can see that there are a bunch of systems for graphics and physics already working but nothing for the audio so it's probably that
For audio you need create custom systems
You can use GameObjects pool with AudioSource components
Or use other audio systems like FMOD
audio source is an officially supported companion object
you should not need your own system or anything like that
internal class CompanionComponentSupportedTypes
{
public static ComponentType[] Types =
{
typeof(Light),
typeof(LightProbeProxyVolume),
typeof(ReflectionProbe),
typeof(TextMesh),
typeof(MeshRenderer),
typeof(SpriteRenderer),
typeof(VisualEffect),
typeof(AudioSource),
typeof(SphereCollider),
typeof(BoxCollider),
typeof(CapsuleCollider),
typeof(MeshCollider),
#if PARTICLE_SYSTEM_MODULE
typeof(ParticleSystem),
typeof(ParticleSystemRenderer),
#endif
#if SRP_7_0_0_OR_NEWER
typeof(Volume),
#endif
#if URP_7_0_0_OR_NEWER
typeof(UnityEngine.Rendering.Universal.DecalProjector),
#endif
#if HDRP_7_0_0_OR_NEWER
typeof(UnityEngine.Rendering.HighDefinition.DecalProjector),
typeof(HDAdditionalLightData),
typeof(HDAdditionalReflectionData),
typeof(PlanarReflectionProbe),
typeof(LocalVolumetricFog),
#endif
#if URP_7_0_0_OR_NEWER
typeof(UniversalAdditionalLightData),
#endif
#if HYBRID_ENTITIES_CAMERA_CONVERSION
typeof(Camera),
#if HDRP_7_0_0_OR_NEWER
typeof(HDAdditionalCameraData),
#endif
#if URP_7_0_0_OR_NEWER
typeof(UniversalAdditionalCameraData),
#endif
#endif
#if SRP_17_0_0_OR_NEWER
typeof(ProbeVolume),
typeof(ProbeVolumePerSceneData),
#endif
};
}```
unity supports companion gameobjects for these components
Is it in the documentation somewhere at all?
no idea sorry, never read it
documentation was non-existent when i learnt dots so i've always learnt from just reading the source
Perhaps it is supported in experimental mode
it's been a feature since 1.0
Interesting
the graphics documentation mentions it
as it can optionally enable companion objects for the camera
I saw it but of course all the other components are not mentioned in the graphics documentation, maybe it still has to be updated
Can i get link?
but yeah if you just put an audiosource in your scene
it will auto attach/create it as a companion object
setup all the transform syncing etc
@thorny fulcrum Thank you I'm not an idiot then
Actually, this is the first time I've heard about companions, to be honest
anyway it's working fine
i haven't used it in ages as i have my own companion solution
that automatically adds a bunch of other stuff like pooling
so i actually force disable audio sources from companion objects
but just loading in test project, yeah working fine
So we has companions in just ecs and ghost presentations in Netcode
@thorny fulcrum I think the problem is just that I call Play in the system, if I disabled and enable the component should work just fine
with play on awake enabled
that is odd, i do remember having weird issues with audio sources in the past
To be honest, I would not use something that is almost not written in the documentation and that does not work in your case
It may break a few more times later
it's very supported/official
the question is really more just, what happens in 6.6
i asked unity about this a while ago and they were like, they probably don't need companion objects in 6.6 but they will probably continue to exist to start with
That also what I was thinking so I seriously started learning how ECS works right now
that said, it'll probably just work exactly how you're using it
just with the gameobject/components directly on the entity
just not via the component system anymore
but until 6.6 drops we can't say for certain how integration will work
I will do only tests with Audiosource and I will comeback with the results
without doing pools, but simply using the companion
just to understand
To be honest, I'm surprised it's still not mark obsolete
why would it be?
it's an internal solution that you don't interact with
and if replaced in 6.6 the user would interact with it the same way
directly interacting with the audio source
It may not have been updated since 2022 according to logs
Also netcode for entities has self companion system
that is definitely being removed at some point
in favour of their new gameobject workflow they just added backend in 1.11
which will be eventually merged to 6.6 entities changes
but the last change to companion system was in 1.3.14
so not sure what you mean by not updated since 2022
it was updated in 2025
unless you're talking about the new gameobject bridge in 1.11?
I'm talking about AudioSource
(vs the old netcode gameobject presentation layer)
why would it need changes?
it's 1 line of code
you add type to list, that's it
That explains everything
you can even make anything work with it btw with internal access
I did a simple Play every tot seconds
var types = CompanionComponentSupportedTypes
.Types
.Concat(new ComponentType[]
{
typeof(CinemachineCamera),
typeof(CinemachineFollow),
typeof(CinemachinePositionComposer),
typeof(CinemachineSplineDolly),
typeof(CinemachineOrbitalFollow),
typeof(CinemachineRotationComposer),
typeof(CinemachineFreeLookModifier),
typeof(CinemachinePanTilt),
typeof(CinemachineRotateWithFollowTarget),
typeof(CinemachineHardLockToTarget),
typeof(CinemachineHardLookAt),
typeof(CinemachineSplineDollyLookAtTargets),
typeof(CinemachineBasicMultiChannelPerlin),
typeof(CinemachineGroupFraming),
typeof(CinemachineFollowZoom),
typeof(CinemachineCameraOffset),
typeof(CinemachineRecomposer),
typeof(CinemachineVolumeSettings),
})
.ToList();```
now, cinemachine works with it!
Btw you can add AudioSource in Query
It's a pity that this system doesn't use UnityObjectRef
i've thought about this a bit but
why would you want to
there's overhead everytime you call UnityObjectRef.Value
Like this:
yep, just saves you doing the exists check
I got it
^ to me the only reason is if you want to support UNITY_DISABLE_MANAGED_COMPONENTS
but i suspect most users don't even know this is an option
More than referring to the ManagedEntityComponentStore?
Guys where should I use UnityObjectRef?
Well, they're just convenient
public object GetManagedComponent(int index)
{
return m_ManagedComponentData[index];
}```
i doubt you can be faster than this
Okay, I'll make a benchmark tomorrow
vs doing an engine call
This is just for baking time right?
Well Baking supports managed components too
UnityObjectRef is ref to managed component but UnityObjectRef is unmanaged component
Ok so, what if I use it inside the AudioSourceComponentData instead of querying the AudioSource?
*is not component is field for unmanaged component
If you already have a link to it, then it's better not to duplicate it
Well in my case "my link" is querying all the managed Audiosources I guess
right?
Idk
I think it's better to use UnityObjectRef only in components that should be structures
Well if use it in singletons is not bad
i mean you're not having 100k gameobjects
so i doubt for most cases that unityobjectref is ever going to be a problem
But less code
for the record, i use unityobjectref myself
for my companion solution
because i'm aiming to disable support for managed components
Yep just did it with unityobjectref, works just fine
passing it with baker
Thank you guys really boosted my knowledge
slightly concerned about this for you in builds
i'd check this still works
i'm pretty sure the companion object isn't the same as the object in the unityobjectref
so i think you're duplicating sources
but it's been ages since i looked at this
There everywhere clone
try just == AudioSources
No I mean, I know it's not the same because my gameobject is not called ...(clone)
ok
companion it is
UnityObjectRef could be usefull for clips for examples I think
if passed trough baker
or scriptable objects?
For any prefabs and read only data
Yep
Everything starts to make sense to me, thank guys
@queen lagoon @thorny fulcrum May I close the post?
Yes
@thorny fulcrum @queen lagoon FYI I opened a discussion post here, they sent a link for the DOCS: https://discussions.unity.com/t/missing-ecs-documentation-for-companion-components/1705963
And even here there is no AudioSource
Yep because this is the ECS Graphics DOCS
It should be like in the main Entities DOCS
I hope they will unify this
@queen lagoon I was always going back and forward trying to understand what was happening and then I realized this😁
Yes Companions are in Unity.Entities.Hybrid.dll
@queen lagoon Official Unity Staff confirmed missing and misleading DOCS