MU Behavior Switcher
The MUBehaviorSwitcher component enables dynamic switching of MU (Movable Unit) behavior between Standard, GuidedMU, and KinematicMU modes at runtime. This component is essential for scenarios where MUs transition between different transport zones with different control requirements.
Overview
In complex automation systems, MUs often need to change their movement behavior as they traverse different zones. For example, an MU might start with standard physics-based movement, enter a guided track section requiring constrained motion, then move to a high-precision area using kinematic positioning. The MU Behavior Switcher automates these transitions based on sensor triggers or PLC signals.

When to Use
MU Behavior Switcher is ideal for:
Track Entry/Exit Systems – MUs entering or exiting guided rail sections need to switch between free and constrained movement
Multi-Zone Transport – Production lines with different conveyor types (standard belts, guided tracks, precision conveyors)
Performance Optimization – Switch to kinematic mode in complex areas to reduce physics overhead
PLC-Controlled Zones – Industrial systems where zone behavior is controlled by external signals
Flexible Production Flow – Dynamic routing systems where MU behavior adapts to production requirements
Behavior Types
Standard
Standard MU behavior uses full physics simulation with a dynamic rigidbody. The MU moves via forces applied by transport surfaces and responds to collisions and gravity. This is the default behavior for MUs without GuidedMU or KinematicMU components.
Use Standard behavior for:
Free-moving MUs on standard conveyors
MUs requiring realistic physics interactions
General-purpose transport scenarios
Guided
GuidedMU behavior uses physics-based movement with ConfigurableJoint constraints. The MU remains a dynamic rigidbody but is constrained to follow guided surfaces along defined paths. Forces are still applied through the physics engine.
Use Guided behavior for:
Curved track sections
Rail-guided transport systems
Guided conveyors where physics interaction is important
See Guided Transport for detailed information.
Kinematic (Pro)
KinematicMU behavior uses fully kinematic positioning without physics simulation. The MU's rigidbody is set to kinematic and moved using MovePosition() and MoveRotation(). This provides precise path following without physics overhead.
Use Kinematic behavior for:
Position-controlled transport from PLCs
High-precision conveyor systems
Complex transport with many MUs (performance optimization)
Systems where physics-based movement causes instability
See KinematicMU (Pro) for detailed information.
Setup
Basic Setup
Add Component: Add the
MU Behavior Switchercomponent to your MU GameObject (requires MU component)Set Target Behavior: Choose the behavior type to switch to (Standard, Guided, or Kinematic)
Configure Switching: Enable automatic switching and assign trigger sensors
Adjust Settings: Configure raycast length and layer mask for guided/kinematic modes
Sensor-Triggered Switching
For automatic zone-based switching:
Create Trigger Sensor: Add a Sensor component where the MU should switch behaviors
Configure Sensor: Set up the sensor's trigger collider at the zone boundary
Assign to Switcher: Drag the sensor to the
Switch To Target SensorfieldEnable Auto Switch: Ensure
Auto Switch On Sensoris checkedTest: Run the simulation and verify the MU switches when entering the sensor

Bidirectional Switching
To switch back to the previous behavior:
Enable Switch Back: Check the
Auto Switch BackoptionAssign Back Sensor: Create and assign a sensor where the MU should revert
Test Both Directions: Verify switching works in both directions
Signal-Based Switching
For PLC or programmatic control:
Create PLC Signal: Add a PLCOutputBool signal to your control logic
Assign Signal: Drag the signal to the
Signal SwitchfieldControl Programmatically: Set the signal value to trigger switches (rising edge detection)
Example:
// Trigger a behavior switch via signal
plcSignal.Value = true; // Rising edge triggers the switchProperties
Behavior Configuration
Current Behavior (MUBehaviorType) Auto-detected behavior type based on attached components. This is read-only and updates when behaviors are switched. Shows Standard if no GuidedMU or KinematicMU component exists, Guided if GuidedMU is attached, or Kinematic if KinematicMU is attached (Pro only).
Target Behavior (MUBehaviorType) The behavior type to switch to when triggered by a sensor or signal. Choose between Standard, Guided, or Kinematic modes depending on your transport requirements.
Automatic Switching
Auto Switch On Sensor (boolean) Controls whether the switcher automatically triggers when the MU enters the switch sensor. When enabled, the behavior switches immediately upon sensor entry without requiring manual triggering. Disable this for manual or signal-only control.
Auto Switch Back (boolean) Enables automatic switching back to the previous behavior when the MU enters the designated back sensor. Useful for creating zones where the MU temporarily uses a different behavior then reverts to its original mode.
Trigger Configuration
Switch To Target Sensor (Sensor) The sensor component that triggers the switch to the target behavior. When the MU enters this sensor's trigger zone and Auto Switch On Sensor is enabled, the behavior switches immediately. Place this sensor at zone boundaries where behavior should change.
Switch Back Sensor (Sensor) The sensor that triggers switching back to the previous behavior. Only active when Auto Switch Back is enabled. Use this to define zones where specific behaviors apply, with automatic reversion when leaving the zone.
Signal Switch (PLCOutputBool) PLC signal that triggers behavior switching using rising edge detection. When the signal transitions from false to true, the switch is triggered. This enables programmatic control from PLC logic or custom scripts.
Behavior Settings (Preserved Across Switches)
Raycast Length (float) Distance in meters for the downward raycast used by GuidedMU and KinematicMU to detect transport surfaces. Default is 0.3 meters. Increase this value if your MUs are positioned higher above the transport surface, decrease for MUs close to the surface. This setting is preserved when switching between behavior types.
Raycast Layer (LayerMask) Defines which Unity layers are checked when raycasting for transport surfaces. Typically includes layers like rvTransport and rvSimStatic. Only objects on these layers will be detected as valid guided surfaces. This setting is preserved across behavior switches.
Debug Mode (boolean) Enables debug visualization and console logging for the switcher. When active, shows raycast lines in the scene view and logs all switching operations to the console. Useful for troubleshooting sensor triggers and behavior transitions. This setting is preserved across switches.
Methods
The component provides public methods for programmatic control:
SwitchTo(MUBehaviorType targetType) Switches the MU to the specified behavior type, handling all cleanup and component management automatically.
SwitchToTarget() Switches the MU to the configured target behavior. Same as calling SwitchTo(TargetBehavior).
SwitchBack() Switches the MU back to the previous behavior type. Useful for programmatic control of zone-based behaviors.
Example usage:
var switcher = mu.GetComponent<MUBehaviorSwitcher>();
// Switch to a specific behavior
switcher.SwitchTo(MUBehaviorType.Kinematic);
// Switch to the configured target
switcher.SwitchToTarget();
// Switch back to previous behavior
switcher.SwitchBack();Events
EventBehaviorSwitched Event triggered when the behavior is successfully switched. Provides the old and new behavior types as parameters, allowing custom logic to respond to behavior changes.
Example subscription:
void Start() {
var switcher = GetComponent<MUBehaviorSwitcher>();
switcher.EventBehaviorSwitched += OnBehaviorChanged;
}
void OnBehaviorChanged(MUBehaviorType from, MUBehaviorType to) {
Debug.Log($"MU switched from {from} to {to}");
}How It Works
The MU Behavior Switcher manages component lifecycle automatically:
Detection: On Start, detects the current behavior by checking which components are attached (GuidedMU, KinematicMU, or neither for Standard)
Trigger Monitoring: Monitors sensor events and PLC signals in FixedUpdate for switch triggers
Settings Preservation: Before removing the current component, stores critical settings (RaycastLength, RaycastLayer, DebugMode)
Cleanup: Performs behavior-specific cleanup:
GuidedMU: Destroys the ConfigurableJoint component
KinematicMU: Calls
PhysicsOn()to restore dynamic rigidbody stateStandard: No special cleanup needed
Component Management: Removes the old behavior component and adds the new one
Settings Transfer: Applies the preserved settings to the new component
Event Notification: Fires the
EventBehaviorSwitchedevent for custom logic
Common Use Cases
Zone-Based Transport System A production line with three zones: standard conveyor entry, guided curved section, and precision kinematic assembly area. MUs automatically switch behaviors as they progress through each zone using strategically placed sensors.
Track Entry/Exit MUs running freely on standard conveyors switch to GuidedMU when entering a guided rail section, then switch back to Standard when exiting. Two sensors control the bidirectional switching automatically.
Performance Optimization A complex simulation with hundreds of MUs switches to KinematicMU in congested areas to reduce physics overhead, maintaining Standard behavior in sparse areas for realistic interactions.
PLC-Controlled Zones An industrial system where production modes are controlled by PLC logic. Signal-based switching enables MUs to adapt their behavior based on real-time production requirements and zone configurations.
Flexible Routing A warehouse automation system where MUs dynamically switch between free movement in open areas and guided movement on AGV paths, controlled by routing algorithms.
Best Practices
Sensor Placement: Position switch sensors slightly before the actual zone boundary to ensure smooth transitions. This gives the component time to perform cleanup and add new components before the MU enters the critical area.
Layer Configuration: Always configure the Raycast Layer to match your transport surface layers. Missing layer assignments are a common cause of GuidedMU and KinematicMU not detecting surfaces properly.
Debug Mode: Enable Debug Mode during initial setup to visualize raycasts and log switching operations. Disable it in production for optimal performance.
Behavior Compatibility: Ensure your transport surfaces support the target behavior type. KinematicMU and GuidedMU require surfaces implementing the IGuidedSurface interface.
State Preservation: The switcher preserves common settings (raycast, layers, debug), but behavior-specific state is not transferred. Design your system so MUs can safely switch at any time.
Performance: Switching behavior has minimal performance impact, but avoid rapid switching (multiple times per second) as it involves component destruction and creation.
Troubleshooting
MU doesn't switch when entering sensor:
Verify the sensor's collider is set to "Trigger"
Check that the MU's collider is on a layer detected by the sensor
Ensure
Auto Switch On Sensoris enabledEnable Debug Mode and check console for switching messages
MU falls through surface after switching:
Check that Raycast Layer includes the transport surface layer
Increase Raycast Length if the MU is positioned high above the surface
Verify the transport surface implements
IGuidedSurfacefor Guided/Kinematic modes
KinematicMU option not available:
KinematicMU requires realvirtual Professional version
Verify Professional is installed and activated
Physics behaves incorrectly after switch:
This is usually due to incomplete cleanup. Enable Debug Mode to verify cleanup steps
Ensure the MU's rigidbody is not manually modified by other scripts during switching
Settings not preserved across switches:
Only RaycastLength, RaycastLayer, and DebugMode are automatically preserved
Other behavior-specific settings must be managed manually via the EventBehaviorSwitched event
See Also
© 2025 realvirtual GmbH https://realvirtual.io - All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form or by any means, including printing, saving, photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the publisher.
Last updated