warvulture

This commit is contained in:
Ferdinando 2026-08-13 19:13:24 +02:00
commit d79f78e9f0
10 changed files with 901 additions and 90 deletions

View file

@ -163,35 +163,23 @@ namespace RacesOfValheim
private static void Clone(GameObject source, Transform parentBone, string namePrefix)
{
GameObject copy = Object.Instantiate(source, parentBone);
copy.name = namePrefix + source.name;
// Through BorrowEffect, which builds the copy inside an inactive holder and strips it
// there. This used to instantiate straight onto the bone and clean up afterwards, and
// "afterwards" is a frame too late: a borrowed node gets its Awake the moment it lands
// on a live player. That is what left burnt-in torches in people's worlds when the head
// flame did the same thing - see the note on FlameSourcePrefabs. Nothing on a creature
// is known to be as expensive as an ItemDrop, but the eye glow reads whatever the
// creature happens to carry, which is exactly the kind of place that surprise comes
// from.
GameObject copy = SkeletonVisuals.BorrowEffect(source, parentBone, namePrefix + source.name,
true, "Skeleton");
if (copy == null) return;
// The pose it was authored at on the creature. Instantiate keeps the world transform,
// which for a prefab means nothing useful.
copy.transform.localPosition = source.transform.localPosition;
copy.transform.localRotation = source.transform.localRotation;
copy.transform.localScale = source.transform.localScale;
// Allowlist, not a blocklist - the same rule the head flame is built under. Whatever
// else rode along (an AnimEvent, a collider, a script that expects a Character above
// it) goes, whatever type it turns out to be; what is left is a light and the things
// that draw it.
foreach (Component comp in copy.GetComponentsInChildren<Component>(true))
{
if (comp is Transform || comp is Light || comp is ParticleSystem ||
comp is ParticleSystemRenderer || comp is MeshRenderer || comp is MeshFilter)
{
continue;
}
Object.Destroy(comp);
}
// A creature can leave its own effects switched off for a script to turn on later, and
// that script is exactly what was just destroyed.
copy.SetActive(true);
foreach (Light light in copy.GetComponentsInChildren<Light>(true)) light.enabled = true;
foreach (Renderer renderer in copy.GetComponentsInChildren<Renderer>(true)) renderer.enabled = true;
}
/// <summary>