Sound damping not working (and then concerns about GameObject.isStatic)

Discuss coding questions, pull requests, and implementation details.
Post Reply
User avatar
pango
Posts: 3347
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Sound damping not working (and then concerns about GameObject.isStatic)

Post by pango »

Some time ago I came across some code in EnemySounds supposed to do some inexpensive sound damping approximation; Lowering the volume of sounds coming from enemies that have no line of sight to the player, checked with a raycast.
This evening I experimented a bit with this feature, and found no difference when listening to a pacified fire daedra around a corner and just slightly ahead where I could see it directly.
I instrumented the code (Unity Editor doesn't work very well under Linux, I rely MonoDevelop for editing and on log messages instead), and discovered that the "CombinedModels" object that was hit by the raycasts was not static, so was not considered for sound damping.
Searching further, I read that the GameObject.isStatic attribute is "Editor only"; And indeed damping works in Unity Editor, just not in standalone player.
What I wonder now, is not only whether this flag can be read by the standalone player (seems it can't) but also if it can be written by the standalone player to make some GameObjects static, something that I do not know how to test...
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
UserOfThisSite
Posts: 20
Joined: Thu Mar 07, 2019 10:05 pm

Re: Sound damping not working (and then concerns about GameObject.isStatic)

Post by UserOfThisSite »

Yes, static flag is editor only and used for optimization stuff like lighting and generation of nav meshes. When the game is built, the game doesn't know if object is static or not, this flag doesn't even exist in the game itself.

You'll have to make a gameobject tag, add it to all static objects (either manually or make an editor script for that) and check for this tag instead of .isStatic. I don't know what objects exactly static is in DFU and how exactly static flag is applied to them, if the game instantiates some objects and then makes them static, then instead add the tag to it in the script, where they're instantiated. If the prefabs themselves have static flag, then change the prefabs by giving them your custom tag.
If I sound rude, please ignore it, that's how I communicate. I'm actually very non-emotional and thus the chances that I'm angry while posting are ~0%. I also use sarcasm very often.

User avatar
pango
Posts: 3347
Joined: Wed Jul 18, 2018 6:14 pm
Location: France
Contact:

Re: Sound damping not working (and then concerns about GameObject.isStatic)

Post by pango »

That property is used in several other places...

Code: Select all

ᐅ git grep isStatic
Binary file Assets/Game/Addons/CSharpCompiler/Plugins/mcs.dll matches
Assets/Scripts/Game/EnemySenses.cs:                if (hit.transform.gameObject.isStatic)
Assets/Scripts/Game/EnemySounds.cs:                if (hit.transform.gameObject.isStatic || door)
Assets/Scripts/Game/PlayerCrush.cs:                    if (moveScanner.HeadRaycastHit.transform.gameObject.isStatic)
Assets/Scripts/Utility/GameObjectHelper.cs:                go.isStatic = true;
Assets/Scripts/Utility/GameObjectHelper.cs:                go.isStatic = true;
Assets/Scripts/Utility/RDBLayout.cs:            bool isStatic = (dfUnity.Option_SetStaticFlags && !overrideStatic) ? true : false;
Assets/Scripts/Utility/RDBLayout.cs:            GameObject go = GameObjectHelper.CreateDaggerfallMeshGameObject(modelID, parent, isStatic, null, ignoreCollider);
Assets/Scripts/Utility/RMBLayout.cs:                go.isStatic = true;
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart

User avatar
Interkarma
Posts: 7236
Joined: Sun Mar 22, 2015 1:51 am

Re: Sound damping not working (and then concerns about GameObject.isStatic)

Post by Interkarma »

The short answer is that I was unaware isStatic was only tracked when executing in editor. I make lots of mistakes and this is one of them. :)

The purpose of setting this flag is mainly to determine what is a fixed object (e.g. the walls and floor) and what isn't (everything else). There's not much more to it than that, fortunately.

Setting a tag isn't a bad idea, and should generally be OK as the objects that are marked as static aren't currently tagged with anything else.

Thanks for the heads-up, I might spend a little time reworking this today.

Post Reply