Skip to content

Commit 8f9b1d1

Browse files
committed
Fixed issues where users could create node before ros2ForUnity was initalized properly
Signed-off-by: Adam Dabrowski <[email protected]>
1 parent 9730b6b commit 8f9b1d1

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/Ros2ForUnity/Scripts/ROS2UnityComponent.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,29 @@ public bool Ok()
4949
}
5050
}
5151

52-
void Awake()
52+
public LazyConstruct()
5353
{
54-
if (ros2forUnity == null)
55-
{
56-
lock (mutex)
57-
{
58-
ros2forUnity = new ROS2ForUnity();
59-
nodes = new List<ROS2Node>();
60-
ros2csNodes = new List<INode>();
61-
executableActions = new List<Action>();
62-
}
54+
lock (mutex)
55+
{
56+
if (ros2forUnity != null)
57+
return;
58+
59+
ros2forUnity = new ROS2ForUnity();
60+
nodes = new List<ROS2Node>();
61+
ros2csNodes = new List<INode>();
62+
executableActions = new List<Action>();
6363
}
6464
}
6565

66+
void Start()
67+
{
68+
LazyConstruct();
69+
}
70+
6671
public ROS2Node CreateNode(string name)
6772
{
73+
LazyConstruct();
74+
6875
lock (mutex)
6976
{
7077
foreach (ROS2Node n in nodes)
@@ -97,6 +104,8 @@ public void RemoveNode(ROS2Node node)
97104
/// </summary>
98105
public void RegisterExecutable(Action executable)
99106
{
107+
LazyConstruct();
108+
100109
lock (mutex)
101110
{
102111
executableActions.Add(executable);

0 commit comments

Comments
 (0)