Page 1 of 1

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

Posted: Sun Apr 21, 2019 12:42 am
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...

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

Posted: Sun Apr 21, 2019 3:07 am
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.

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

Posted: Sun May 05, 2019 5:32 am
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;

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

Posted: Mon May 06, 2019 12:20 am
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.