carla-simulator / carla

Open-source simulator for autonomous driving research.
http://carla.org
MIT License
10.66k stars 3.42k forks source link

RuntimeError: Unknown error while trying to spawn actor #4363

Open dbersan opened 2 years ago

dbersan commented 2 years ago

Carla version: 0.9.11

I tried following the tutorial to add Props to carla here. More specifically, I followed the "Ingestion in a build from source", i.e., I have a locally compiled Carla, which I run through Unreal Engine.

Added the files to the Import/ folder exactly like the tutorial described:

carla/ --Import/ ----Package01/ ----|--Package01.json ----|--Props/ ----|--|--Ball/ ----|--|--|--Ball.fbx

Package01.json:

{
    "maps": [
    ],
    "props": [
      {
        "name": "Football",
        "size": "small",
        "source": "./Props/Ball/Ball.fbx",
        "tag": "Other"
      }
    ]
  }

Used this object.

I ran make import, make PythonAPI and make launch in this order, and then started simulation inside Unreal Editor.

I tried spawning it (world.spawn_actor()...), even though it finds it on the Blueprint list (with blueprint_library.filter('static.prop.football')[0]), I get an error:

RuntimeError: Unknown error while trying to spawn actor

Also tried exporting it as a package and importing to a pre-compiled carla installation. Got the same error when trying to spawn.

edit: Tried with this object instead now. Didn't get any error, but I can't see anything spawned on the map.

dbersan commented 2 years ago

I noticed the error happens when the asset doesn't appear as "static mesh" inside Unreal, (e.g, "Skeletal Mesh"). But there is nowhere explaining how to export from Blender to Carla an .fbx file that is a "static mesh".

GustavoSilvera commented 2 years ago

Hi, I was facing the exact same issue when trying to spawn new props and I found a valid workaround (for props at least).

If you look at carla/Unreal/CarlaUE4/Content/Carla/Config/Default.Package.json this file defines a large list of valid props and their static mesh source destinations as spawnable props in CarlaUE4.

With this, I was able to add a new_prop after the last one (Calibrator in 0.9.11) that looked like:

{
    "name": "new_prop",
        "path": "/Game/Carla/Static/Static/SM_new_prop.SM_new_prop",
    "size": "Medium" # or whatever size estimation you'd like
}

Of course ensure you correctly have valid static mesh path file (note that the file does have a .uasset filetype, but in the json you should still denote it as SM_new_prop.SM_new_prop instead of SM_new_prop.uasset).

Then after a quick relaunch of the editor you should be able to now spawn your new_prop from the blueprint library as follows:

bp = list(blueprint_library.filter("static.prop.new_prop"))[0]
transform = world.get_map().get_spawn_points()[0] # or choose any other spawn point
world.spawn_actor(bp, transform) # should succeed with no errors

Note that I've only tested this in Town03, and interestingly some of the additional (opt) maps (in 0.9.11) have their own .Package.json files which you might need to modify similarly to reflect in those maps.

ChengHuang-CH commented 2 years ago

I also experienced the same issue and solved it after several tests.Thanks for @GustavoSilvera mentioning the existence of the file *.Package.json, I was able to find out the problem, which is caused by the naming rules-- "Override FullName" of UE4 while importing the .fbx file.

For example, my static mesh name in Blender is "MeshName", and the exported .fbx file is "FbxName.fbx". After importing all files into carla environment following offical instructions, I find that the static mesh name became "FbxName_MeshName" instead of the expected "FbxName" inside the UE4 content folder. My solution is to revise the "FbxName.FbxName" to "FbxName_MeshName.FbxName_MeshName" in the generated *.Package.json file after checking the real name.

All in all, it is important to check the real name of the imported static mesh inside the content folder of UE4, and see if it is the same as in (your_map_name).Package.json file.

(Besides, I cannot just import new props by filling the"props" content and leave the"maps" content empty in the json file, it is necessary for me to add new map files ( .fbx and .xodr) at the same time, otherwise, "import_assets_from_json_list if "tile_size" in maps[0]: IndexError: list index out of range" issue will break the process of importing new props. And I didn't figure out the reason behind)

crabiner commented 2 years ago

I also faced the same issue in Carla version: 0.9.12 modified the generated *.Package.json file as you said to"FbxName_MeshName.FbxName_MeshName" and it fixed it

crabiner commented 2 years ago

(Besides, I cannot just import new props by filling the"props" content and leave the"maps" content empty in the json file, it is necessary for me to add new map files ( .fbx and .xodr) at the same time, otherwise, "import_assets_from_json_list if "tile_size" in maps[0]: IndexError: list index out of range" issue will break the process of importing new props. And I didn't figure out the reason behind)

@ChengHuang-CH I don't have any "maps" in json and to overcome the error you see try editing Util/BuildTools/Import.py script replace two instances of if "tile_size" in maps[0]: with if len(maps) > 0 and "tile_size" in maps[0]: I also had to comment out the line with copy_roadpainter_config_files(args.package)

ChengHuang-CH commented 2 years ago

@ChengHuang-CH I don't have any "maps" in json and to overcome the error you see try editing Util/BuildTools/Import.py script replace two instances of if "tile_size" in maps[0]: with if len(maps) > 0 and "tile_size" in maps[0]: I also had to comment out the line with copy_roadpainter_config_files(args.package)

@crabiner Thanks for your helpful comments. Your solution works for me by revising the line 456 and line 467 from "tile_size" in maps[0] to len(maps) > 0 and "tile_size" in maps[0] in Util/BuildTools/Import.py. And line 646 needs to be commented if roadpainter_decals.json file doesn't exist. Thanks!

bernatx commented 2 years ago

Hi folks, You are right, it seems there are some problems when importing props without a map. I'm fixing that.

The problem with the nomenclature adding the FBX name before the asset is because now you can import maps in tiles, and then we need to avoid conflicts between assets with the same name from different tiles, that is why we add the FBX name as a prefix.

Regards

crabiner commented 2 years ago

I am able to spawn the props using python API when pressing play in UE4 editor, but when running from a carla package created by "make package" I still get "RuntimeError: Unknown error while trying to spawn actor"

GustavoSilvera commented 2 years ago

Hello all,

I found that I also am having this problem when trying to spawn custom props in shipping (package) mode. The issue for me was that the props were not being cooked by UE4's UAT script, so the props were unable to be spawned in the package mode. You should be able to check if this is the case for you by seeing if find $SHIPPING_DIR -type f -name '$YOUR_PROP.*' does not return a .uasset and .uexp file.

If this is the case for you, I figured out how to solve this as follows:

Then running make package should include these new props in the cooking script.

You should be able to verify this works by ensuring that within the build directory there exists a CarlaUE4/Content/MyProps/SM_CustomProp.uexp file AND a CarlaUE4/Content/MyProps/SM_CustomProp.uasset file. (both are required else it won't work)

If the above steps didn't work for you, you might be successful by modifying Util/Build/Package.sh by adding the flags -CookAll -IgnoreCookErrors where the RunUAT.sh BuildCookRun command is being run (line 111 in 0.9.11). (Theoretically the same should translate for Windows .bat's) which will forcefully cook everything in the Content/ directory, but will take much longer and probably does more than what you want.

After trying both methods, the first (modifying DefaultGame.ini) worked cleanly for me and I can verify that I'm able to spawn my custom props through the PythonAPI as desired while in the shipping (package) mode.

Hope this helps!

chengguizi commented 2 years ago

I also encountered the issue that make pacakge ARGS="--packages=<package>" does not cook props correctly in 0.9.12. This results in unable to spawn props when being imported to packaged Carla.

The fix for me is to add after this line

MapPathDataLinux.Append(PropsMapPath + TEXT("/PropsMap"));

I believe the cause is the missing PropsMap when cooking for Linux version. Hope it helps!

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

YHao29 commented 1 year ago

@GustavoSilvera hello, I'm so excited that you give me some hope. But I still meet some problem about using my own prop.

Prepares

I use the docker version of carla 0.9.13 and I have design a new prop then import to the docker following this guide. . After I run the ./ImportAssets.sh, I can see a Package01 has been created in the filefolder : image

Problem

But when I want to spawn it to the world, I can not find it in the blueprint. And I also don't know how to use it like other props ('static.prop.bench01').

Question

Could you teach me that how to use the props I just import to the carla docker? thanks for your time

2019211753 commented 9 months ago

In Carla_0.9.14, it's still a problem. and i solved it by @GustavoSilvera's solution. However, my path is the absolute path instead of the path "/Game/..."

lsangreg commented 8 months ago

Hello, I followed your instruction and i was able to obtain a correct package from ue4 to carla, with .uexp and .uasset files. The problem now is that I still get the error RuntimeError: Unknown error while trying to spawn actor When i try to spawn the actor! I can find the Blueprint in the list ActorBlueprint(id=static.prop.pallet,tags=[pallet, prop, static]) but then the unknown error arrives, I also added my own lines in Default.Packages.json of the simulator /CarlaUE4/Content/Carla/Config


                {
            "name": "Pallet",
            "path": "/Game/Pallet/Static/Other/Pallet/pallet.pallet",
            "size": "medium"
        }```
Croquembouche commented 1 month ago

This is still an issue.

Blyron commented 2 weeks ago

Which is actually the issue? If you have the uasset in content folder then you add properly the path. The spawn works.

lsangreg commented 2 weeks ago

@Croquembouche check this https://github.com/carla-simulator/carla/issues/6789

ShaharShakiUnreal commented 1 week ago

Hi, I also have this problem. I follow the guides here, but still get the "Unknown error while trying to spawn actor". I was added this guide https://carla.readthedocs.io/en/latest/tuto_A_add_props/#ingestion-in-a-build-from-source and added the fbx file: Import/Package01/Props/bigrashcan/bigtrashcan.fbx also added the Package01 json with this content: { "maps": [ ], "props": [ { "name": "bigtrashcan", "size": "medium", "source": "./Props/bigtrashcan/bigtrashcan.bigtrashcan", "tag": "TrashCan" } ] }

also updated the Default.Package.json with this: { "name": "bigtrashcan", "path": "/Game/Carla/Static/Static/Trashcans/bigtrashcan_Wheels_Auto1.bigtrashcan_Wheels_Auto1", "size": "Medium" }

and still I can see the prop on the blueprint library list, but when spawn it getting the error I mentioned above. can someone please help? thanks.

Blyron commented 1 week ago

How are you trying to spawn it? example code please. Have you tried to get list of all props and see if your big trash can is there?

ShaharShakiUnreal commented 1 week ago

How are you trying to spawn it? example code please. Have you tried to get list of all props and see if your big trash can is there?

Hi, Thanks for you r quick reply. image as you see I get the big trash can in the props list. But inside the "try" block when I get to the world.spawn_actor I get the error I mentioned above. Thanks

Blyron commented 1 week ago

Print in console of static.prop and see what happens It may be there

ShaharShakiUnreal commented 1 week ago

Print in console of static.prop and see what happens It may be there

do you mean like that?: image

Blyron commented 1 week ago

Yes, your bigtrashcan is there as expected, so your method to get it is wrong. Try something like
prop = world.get_blueprint_library().filter("static.prop.bigtrashcan") spawn_point = random.choice(spawn_points) spawn_point.location.z += z

SpawnActor(prop, spawn_point)

ShaharShakiUnreal commented 1 week ago

Yes, your bigtrashcan is there as expected, so your method to get it is wrong. Try something like prop = world.get_blueprint_library().filter("static.prop.bigtrashcan") spawn_point = random.choice(spawn_points) spawn_point.location.z += z

SpawnActor(prop, spawn_point)

But I manage to spawn vehicles without problems: car_actor = world.spawn_actor(car_blueprint, spawn_point)

when I do the same to the trash can it failed. I think the problem might be in the json or naming convention of the files.

Blyron commented 1 week ago

I think is related with you try to get the proper blueprint

ShaharShakiUnreal commented 1 week ago

I think is related with you try to get the proper blueprint

I'm not sure I get it. I'm trying to spawn it as you said, unfortunately it is not working

Blyron commented 1 week ago

prop = world.get_blueprint_library().filter("static.prop.bigtrashcan") spawn_point = carla.Transform() spawn_point.location.z = 200.0 spawn_point.rotation.roll = 0.0 spawn_point.rotation.pitch = 0.0 world.try_spawn_actor(prop, spawn_point)

Is this working?

ShaharShakiUnreal commented 1 week ago

prop = world.get_blueprint_library().filter("static.prop.bigtrashcan") spawn_point = carla.Transform() spawn_point.location.z = 200.0 spawn_point.rotation.roll = 0.0 spawn_point.rotation.pitch = 0.0 world.try_spawn_actor(prop, spawn_point)

Is this working? Getting this error:

Python argument types in World.try_spawn_actor(World, BlueprintLibrary, Transform) did not match C++ signature: try_spawn_actor(class carla::client::World {lvalue}, class carla::client::ActorBlueprint blueprint, class carla::geom::Transform transform, class carla::client::Actor * __ptr64 attach_to=None, enum carla::rpc::AttachmentType attachment_type=carla.libcarla.AttachmentType.Rigid)

Blyron commented 1 week ago
client = carla.Client(args.host, args.port)
client.set_timeout(2000.0)

world = client.get_world()
prop = world.get_blueprint_library().filter("static.prop.bigtrashcan")
spawn_point = carla.Transform()
spawn_point.location.z = 200.0
spawn_point.rotation.roll = 0.0
spawn_point.rotation.pitch = 0.0
world.try_spawn_actor(prop, spawn_point)
ShaharShakiUnreal commented 1 week ago
client = carla.Client(args.host, args.port)
client.set_timeout(2000.0)

world = client.get_world()
prop = world.get_blueprint_library().filter("static.prop.bigtrashcan")
spawn_point = carla.Transform()
spawn_point.location.z = 200.0
spawn_point.rotation.roll = 0.0
spawn_point.rotation.pitch = 0.0
world.try_spawn_actor(prop, spawn_point)

Those 2 lines are not the problem, I got them in my code: client = carla.Client(args.host, args.port) client.set_timeout(2000.0)

This is my current script:

import carla import random import time

def spawn_random_objects_on_roads(client, blueprint_library, num_objects): world = client.get_world()

  # Retrieve bounding boxes for roads
  road_bounding_boxes = world.get_level_bbs(carla.CityObjectLabel.RoadLines)

  total_spawned_objects = 0

  print(len(road_bounding_boxes))

  for bb in road_bounding_boxes:
      if total_spawned_objects >= num_objects:
          break
      # Generate a random spawn point within the bounding box
      location = bb.location
      extent = bb.extent
      spawn_point = carla.Transform(
          carla.Location(
              x=random.uniform(location.x - extent.x, location.x + extent.x),
              y=random.uniform(location.y - extent.y, location.y + extent.y),
              z=location.z + 0.5
          ),
          carla.Rotation(yaw=270)  # Rotate 90 degrees to the right
      )

      # Choose a random car blueprint
      car_blueprints = [bp for bp in blueprint_library if 'vehicle' in bp.tags and 'Bus00' not in bp.id and 'Bus09' not in bp.id]
      car_blueprint = random.choice(car_blueprints)

      try:
          car_actor = world.spawn_actor(car_blueprint, spawn_point)
          if car_actor is None:
              print("Car spawn failed")
              continue

          # Debugging information
          print(f"Spawned car: {car_blueprint.id} at {spawn_point.location}")

          # Spawn the bigtrashcan and attach it to the car
          trashcan_blueprint = next((bp for bp in blueprint_library if 'bigtrashcan' in bp.id), None)
          if trashcan_blueprint is None:
              print("bigtrashcan blueprint not found")
              continue

          trashcan_spawn_point = carla.Transform(
              carla.Location(x=0, y=0, z=1.5),  # Adjust this height to place the trashcan on the roof
              carla.Rotation()
          )

          try:
              prop = world.get_blueprint_library().filter("static.prop.bigtrashcan")
              spawn_point = carla.Transform()
              spawn_point.location.z = 200.0
              spawn_point.rotation.roll = 0.0
              spawn_point.rotation.pitch = 0.0
              world.try_spawn_actor(prop, spawn_point)

              trashcan_actor = world.spawn_actor(trashcan_blueprint, trashcan_spawn_point, attach_to=car_actor)
              if trashcan_actor is None:
                  print("Trashcan spawn failed")
                  continue

              # Debugging information
              print(f"Attached trashcan: {trashcan_blueprint.id} to car: {car_blueprint.id}")

              # Set velocity for the car (and the trashcan should follow)
              car_actor.set_target_velocity(carla.Vector3D(0, -10, 0))  # Negative velocity on y-axis

              total_spawned_objects += 1
              print('spawned')
          except Exception as e:
              print(f"Error spawning trashcan actor: {e}")

      except Exception as e:
          print(f"Error spawning car actor: {e}")

  print(f"Total spawned objects: {total_spawned_objects}")

def main(): client = carla.Client('localhost', 2000) client.set_timeout(2000.0) world = client.get_world() blueprint_library = world.get_blueprint_library()

  num_objects = 1
  spawn_random_objects_on_roads(client, blueprint_library, num_objects)
ShaharShakiUnreal commented 1 week ago
client = carla.Client(args.host, args.port)
client.set_timeout(2000.0)

world = client.get_world()
prop = world.get_blueprint_library().filter("static.prop.bigtrashcan")
spawn_point = carla.Transform()
spawn_point.location.z = 200.0
spawn_point.rotation.roll = 0.0
spawn_point.rotation.pitch = 0.0
world.try_spawn_actor(prop, spawn_point)

I guess you meant: prop = world.get_blueprint_library().filter("static.prop.bigtrashcan") spawn_point = carla.Transform() spawn_point.location.z = 200.0 spawn_point.rotation.roll = 0.0 spawn_point.rotation.pitch = 0.0 world.try_spawn_actor(prop[0], spawn_point)

and that not working either. Its not crashing but the object is not spawned.

Croquembouche commented 3 days ago

Which is actually the issue? If you have the uasset in content folder then you add properly the path. The spawn works.

Hi, I managed to import some props, but some refused to load. These props are from the Unreal Engine and CARLA blueprint. I am trying to package the props in the source version and import them into the prebuilt version.

I will try again later and update this issue with screenshots.