carla-simulator / carla

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

Add to Spawn Actor Function Attributes Map #7661

Closed MTeuberItemis closed 1 week ago

MTeuberItemis commented 2 weeks ago

Im currently trying to add an additional boolean to a walker, so I can set it from python scripts. It should work similar to e.g. "is_invincible". In python it looks like following: walker_bp.set_attribute('is_invincible', 'false')

I tried to figure out, how I can add such a boolean and managed to work my way to the "Spawn Actor" function in the WalkerFactory, where the following node seems to make it work: image

The input, "Attributes", is unfortunately a mystery to me and I can't figure out, where I can add another ID to that Map. image

When I print out the map, the following attributes are included:

LogBlueprintUserMessages: [WalkerFactory_C_0] role_name LogBlueprintUserMessages: [WalkerFactory_C_0] gender LogBlueprintUserMessages: [WalkerFactory_C_0] speed LogBlueprintUserMessages: [WalkerFactory_C_0] is_invincible LogBlueprintUserMessages: [WalkerFactory_C_0] generation LogBlueprintUserMessages: [WalkerFactory_C_0] age

Can someone help me here?

This is carla 0.9.13

Madecu commented 2 weeks ago

Hi @MTeuberItemis, Those attributes are declared in a C++ class. First, you need to add your new variable to the Pedestrians structure. image

Then, define it in ActorBlueprintsFunctionLibrary image

MTeuberItemis commented 1 week ago

Thank you for that input, that already helps a lot. But I still get some errors that I dont really understand.

There are two cases I tested with different outcomes: [everything in carla 0.9.13]

CASE 1:

I added following code: PedestriansParameters.h: line 59 (bottom of the code)

... UPROPERTY(EditAnywhere, BlueprintReadWrite) bool on_wheelchair = false; };

ActorBlueprintFunctionLibrary.cpp: line 1124:

Definition.Attributes.Emplace(FActorAttribute{ TEXT("on_wheelchair"), EActorAttributeType::Bool, GetWheelchair(Parameters.on_wheelchair)});

this resulted in a build error, when I tried to launch my locally built carla: it stopped at module 5/8:

make: *** [CarlaUE4Editor] Fehler 6

CASE 2

inspired by: how "is_invincible" was added, i made no changes to original pedestrianparameters.h and added following to ActorBlueprintFunctionLibrary.cpp: line 1144:

FActorVariation OnWheelchair; OnWheelchair.Id = TEXT("on_wheelchair"); OnWheelchair.Type = EActorAttributeType::Bool; OnWheelchair.RecommendedValues = { TEXT("false") }; OnWheelchair.bRestrictToRecommended = false;

with this it was possible to build, but unfortunately when I tried to spawn walkers, it gave me following error:

Unknown error while trying to spawn actor

Interestingly, "on_wheelchair" also got added to the properties mentioned in my original question:

LogBlueprintUserMessages: [WalkerFactory_C_0] on_wheelchair LogBlueprintUserMessages: [WalkerFactory_C_0] role_name LogBlueprintUserMessages: [WalkerFactory_C_0] gender LogBlueprintUserMessages: [WalkerFactory_C_0] speed LogBlueprintUserMessages: [WalkerFactory_C_0] is_invincible LogBlueprintUserMessages: [WalkerFactory_C_0] generation LogBlueprintUserMessages: [WalkerFactory_C_0] age

MTeuberItemis commented 1 week ago

it was actually a problem in another part of the walkerFactory. the second approach works just fine. thank you