Skip to content

Commit 71ad0ff

Browse files
authored
Merge pull request #197 from hijimasa/feature/for-simulator-app
Made it possible to initialize LiDARSensor later so that it works with the built app.
2 parents c6f5582 + f03347f commit 71ad0ff

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/DepthBufferLiDAR/DepthBufferLiDARSensor.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,17 @@ public class DepthBufferLiDARSensor : LiDARSensor
3838

3939
protected override void Init()
4040
{
41-
base.Init();
41+
if (scanPattern == null)
42+
{
43+
Debug.LogWarning("Initialization postponed: scanPattern is null. Ensure that scanPattern is assigned before calling Init.");
44+
return;
45+
}
46+
Initialize();
47+
}
48+
49+
public override void Initialize()
50+
{
51+
base.Initialize();
4252
_transform = this.transform;
4353
SetupCamera();
4454
LoadScanData();

Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/LiDARSensor.cs

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ public abstract class LiDARSensor : UnitySensor, IPointCloudInterface<PointXYZI>
3434
public int pointsNum { get => _pointsNumPerScan; }
3535

3636
protected override void Init()
37+
{
38+
if (_scanPattern == null)
39+
{
40+
return;
41+
}
42+
Initialize();
43+
}
44+
45+
public virtual void Initialize()
3746
{
3847
_pointsNumPerScan = Mathf.Clamp(_pointsNumPerScan, 1, scanPattern.size);
3948
_pointCloud = new PointCloud<PointXYZI>()

Assets/UnitySensors/Runtime/Scripts/Sensors/LiDAR/RaycastLiDAR/RaycastLiDARSensor.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ public class RaycastLiDARSensor : LiDARSensor
3030

3131
protected override void Init()
3232
{
33-
base.Init();
33+
if (scanPattern == null)
34+
{
35+
Debug.LogWarning("RaycastLiDARSensor: scanPattern is null. Initialization is delayed until scanPattern is set.");
36+
return;
37+
}
38+
Initialize();
39+
}
40+
41+
public override void Initialize()
42+
{
43+
base.Initialize();
3444

3545
_transform = this.transform;
3646

Assets/UnitySensorsROS/Runtime/Scripts/Publishers/SensorMsgs/PointCloud2Msg/LiDARPointCloud2MsgPublisher.cs

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public class LiDARPointCloud2MsgPublisher : PointCloud2MsgPublisher<PointXYZI>
1212

1313
private void Awake()
1414
{
15+
if (_source == null)
16+
{
17+
Debug.LogError("Source is not set in LiDARPointCloud2MsgPublisher. Please ensure that the '_source' field is assigned in the Unity Editor or via code. Expected type: IPointCloudInterface<PointXYZI>.");
18+
return;
19+
}
1520
_serializer.SetSource(_source as IPointCloudInterface<PointXYZI>);
1621
}
1722
}

0 commit comments

Comments
 (0)