Fix sleeping issue

This commit is contained in:
Pascal Serrarens 2026-05-20 17:39:14 +02:00
parent 57967e3409
commit 5584123c20
2 changed files with 11 additions and 3 deletions

View File

@ -102,6 +102,8 @@ namespace NanoBrain.Unity {
cluster = SerializedPropertyUtility.GetManagedObjectForProperty(targetObject, property.propertyPath) as Cluster;
}
else {
// This does not work property yet it seems
Debug.Log("Instantiate");
ClusterPrefab clusterPrefab = prefabProp.objectReferenceValue as ClusterPrefab;
cluster = new(clusterPrefab);
object parent = SerializedPropertyUtility.GetParentObjectAndMember(targetObject, property.propertyPath, out var memberInfo, out int outIndex);

View File

@ -351,13 +351,13 @@ namespace NanoBrain {
/// <summary>
/// True when the neuron is not persisting and has not be updated for timeToSleep seconds
/// </summary>
public virtual bool isSleeping => !persistOutput && (Time.time - this.lastUpdate > this.timeToSleep);
public virtual bool isSleeping => !persistOutput && (Time.time - this.lastUpdate > timeToSleep);
/// <summary>
/// Check if the neuron is sleeping.
/// </summary>
/// This will reset the output value if it is sleeping
public void SleepCheck() {
if (this.isSleeping) {
if (this.isSleeping && this.outputSqrMagnitude > 0) {
#if UNITY_MATHEMATICS
this._outputValue = new float3(0, 0, 0);
#else
@ -373,7 +373,9 @@ namespace NanoBrain {
/// <summary>
/// Time in seconds after the last update the neuron can go to sleep
/// </summary>
public readonly float timeToSleep = 1f;
public static readonly float timeToSleep = 1f;
public bool breakOnUpdate = false;
/// \copydoc NanoBrain::Nucleus::ShallowCloneTo
public override Nucleus ShallowCloneTo(Cluster parent) {
@ -395,6 +397,7 @@ namespace NanoBrain {
clone.curve = this.curve;
clone.activator = this.activator;
clone.curveMax = this.curveMax;
clone.breakOnUpdate = this.breakOnUpdate;
}
/// <summary>
@ -445,6 +448,9 @@ namespace NanoBrain {
/// \copydoc NanoBrain::Nucleus::UpdateStateIsolated
public override void UpdateStateIsolated() {
if (breakOnUpdate) {
Debug.Break();
}
var combination = Combinator(this.bias, this.synapses);
this.outputValue = Activator(combination);
this.lastUpdate = Time.time;