@@ -132,35 +132,18 @@ private void SetEnvPathVariable()
132
132
Environment . SetEnvironmentVariable ( GetEnvPathVariableName ( ) , pluginPath + envPathSep + currentPath ) ;
133
133
}
134
134
135
- private void EnsureROS2PluginVisibility ( )
136
- {
137
- string pluginPath = GetPluginPath ( ) ;
138
- string currentEnvironmentPath = GetEnvPathVariableValue ( ) ;
139
-
140
- if ( string . IsNullOrEmpty ( currentEnvironmentPath ) || ! currentEnvironmentPath . Contains ( pluginPath ) )
141
- {
142
- Debug . LogError ( "environment variables do not contain required settings (variable value | expected): " + currentEnvironmentPath + " | " + pluginPath ) ;
143
- #if UNITY_EDITOR
144
- EditorApplication . isPlaying = false ;
145
- throw new System . InvalidOperationException ( "Missing library path to plugins in environment. Make sure you launch with the start app/editor script " ) ;
146
- #else
147
- const int LD_LIBRARY_PATH_ENTRY_MISSING = 32 ;
148
- Application . Quit ( LD_LIBRARY_PATH_ENTRY_MISSING ) ;
149
- #endif
150
- }
151
- }
152
-
153
135
/// <summary>
154
136
/// Check if the ros version is supported, only applicable to non-standalone plugin versions
155
137
/// (i. e. without ros2 libraries included in the plugin).
156
138
/// </summary>
157
139
private void CheckROSVersionSourced ( )
158
140
{
159
141
string currentVersion = Environment . GetEnvironmentVariable ( "ROS_DISTRO" ) ;
160
- const string supportedVersion = "foxy" ;
142
+ List < string > supportedVersions = new List < string > ( ) { "foxy" , "galactic" } ;
143
+ var supportedVersionsString = String . Join ( ", " , supportedVersions ) ;
161
144
if ( string . IsNullOrEmpty ( currentVersion ) )
162
145
{
163
- string errMessage = "No ROS environment sourced. You need to source your ROS2 " + supportedVersion
146
+ string errMessage = "No ROS environment sourced. You need to source your ROS2 " + supportedVersionsString
164
147
+ " environment before launching Unity. Make sure you launch with the start app/editor script" ;
165
148
Debug . LogError ( errMessage ) ;
166
149
#if UNITY_EDITOR
@@ -172,10 +155,10 @@ private void CheckROSVersionSourced()
172
155
#endif
173
156
}
174
157
175
- if ( currentVersion != supportedVersion )
158
+ if ( ! supportedVersions . Contains ( currentVersion ) )
176
159
{
177
160
string errMessage = "Currently sourced ROS version differs from supported one. Sourced: " + currentVersion
178
- + ", supported: " + supportedVersion ;
161
+ + ", supported: " + supportedVersionsString + "." ;
179
162
Debug . LogError ( errMessage ) ;
180
163
#if UNITY_EDITOR
181
164
EditorApplication . isPlaying = false ;
@@ -185,7 +168,7 @@ private void CheckROSVersionSourced()
185
168
Application . Quit ( ROS_BAD_VERSION_CODE ) ;
186
169
#endif
187
170
}
188
- Debug . Log ( "Running with a supported ROS 2 version: " + supportedVersion ) ;
171
+ Debug . Log ( "Running with a supported ROS 2 version: " + currentVersion ) ;
189
172
}
190
173
191
174
private void RegisterCtrlCHandler ( )
@@ -210,13 +193,17 @@ private void ConnectLoggers()
210
193
211
194
internal ROS2ForUnity ( )
212
195
{
196
+ // TODO: Find a way to determine whether we run standalone build
213
197
if ( GetOS ( ) == Platform . Windows ) {
198
+ // Windows version can run standalone, modifies PATH to ensure all plugins visibility
214
199
SetEnvPathVariable ( ) ;
215
200
} else {
216
- EnsureROS2PluginVisibility ( ) ;
201
+ // Linux version needs to have ros2 sourced, which is checked here. It also loads plugins by absolute path
202
+ // since LD_LIBRARY_PATH cannot be set dynamically within the process for dlopen() which is used under the hood.
203
+ // Since libraries are built with -rpath=".", dependencies will be correcly located within plugins directory
204
+ CheckROSVersionSourced ( ) ;
205
+ ROS2 . GlobalVariables . absolutePath = GetPluginPath ( ) + "/" ;
217
206
}
218
- // TODO: Find a way to determine whether we run standalone build
219
- //CheckROSVersionSourced();
220
207
ConnectLoggers ( ) ;
221
208
Ros2cs . Init ( ) ;
222
209
RegisterCtrlCHandler ( ) ;
0 commit comments