diff --git a/Unity/Participant.cs b/Unity/Participant.cs index c3e9fda..cdd163d 100644 --- a/Unity/Participant.cs +++ b/Unity/Participant.cs @@ -50,10 +50,14 @@ namespace RoboidControl.Unity { coreDrive.component = differentialDrive; break; case RoboidControl.Motor coreMotor: - Motor wheel = Motor.Create(coreMotor); - coreMotor.component = wheel; - // We need to know the details (though a binary msg) - // before we can create the wheel reliably + if (coreMotor.component == null) { + Motor wheel = Motor.Create(coreMotor); + coreMotor.component = wheel; + // We need to know the details (though a binary msg) + // before we can create the wheel reliably + } + else // Update the component from the core + coreMotor.component.Init(coreMotor); break; case RoboidControl.Thing coreThing: if (coreThing.component == null) { @@ -69,6 +73,8 @@ namespace RoboidControl.Unity { thing = Thing.Create(coreThing); coreThing.component = thing; } + else // Update the component from the core + coreThing.component.Init(coreThing); break; } } diff --git a/Unity/Thing.cs b/Unity/Thing.cs index 866b7a0..c3091b8 100644 --- a/Unity/Thing.cs +++ b/Unity/Thing.cs @@ -42,7 +42,7 @@ namespace RoboidControl.Unity { /// /// The core of the thing /// This affects the parent and pose of the thing - protected void Init(RoboidControl.Thing core) { + public void Init(RoboidControl.Thing core) { this.core = core; this.core.component = this; // This is wrong, it should get the owner, which is not the siteserver @@ -51,8 +51,8 @@ namespace RoboidControl.Unity { this.owner = core.owner.component; if (core.parent != null && core.parent.component != null) { - this.transform.SetParent(core.parent.component.transform, false); - this.transform.localPosition = Vector3.zero; + this.transform.SetParent(core.parent.component.transform, false); + this.transform.localPosition = Vector3.zero; } else if (core.owner.component != null) { this.transform.SetParent(core.owner.component.transform, false); diff --git a/src/Participant.cs b/src/Participant.cs index 5cb2527..42ac8a9 100644 --- a/src/Participant.cs +++ b/src/Participant.cs @@ -111,9 +111,8 @@ namespace RoboidControl { aThing.owner.networkId == networkId && aThing.id == thingId ); - //Thing thing = things.Find(aThing => Thing.IsThing(aThing, networkId, thingId)); - if (thing == null) - Console.WriteLine($"Unknown Thing {this.networkId} [{networkId}/{thingId}]"); + // if (thing == null) + // Console.WriteLine($"Unknown Thing {this.networkId} [{networkId}/{thingId}]"); return thing; } diff --git a/src/Participants/ParticipantUDP.cs b/src/Participants/ParticipantUDP.cs index 7adb8a4..091ac30 100644 --- a/src/Participants/ParticipantUDP.cs +++ b/src/Participants/ParticipantUDP.cs @@ -465,15 +465,16 @@ namespace RoboidControl { } Thing thing = owner.Get(msg.networkId, msg.thingId); - if (sender.networkId != owner.networkId) { - // Sender forwarded this thing msg - // So this is a remote thing - thing ??= ProcessNewThing(owner, msg, true); + if (thing != null) { + UpdateEvent e = new() { + messageId = ThingMsg.id, + thing = thing + }; + owner.updateQueue.Enqueue(e); } else { - // Sender is the owner of the thing - // So this is a simulated thing - thing ??= ProcessNewThing(owner, msg, false); + bool isRemote = sender.networkId != owner.networkId; + thing = ProcessNewThing(owner, msg, isRemote); } if (msg.parentId != 0) {