Hi all, I want to add a number of SceneComponents to my actor class. The components are just used for organization purposes. I use this code in the constructor of my actor class:
I’m experiencing some issues with this, though. When making a blueprint based on this class, adding static meshes and dragging it into the world, all is fine. However, after saving and reloading the map I always get these messages:
Error Failed import for SceneComponent /Game/Blueprints/Gathering/BP_RN_Chest.Default__BP_RN_Chest_C:ActiveGroup
Error Failed import for SceneComponent /Game/Blueprints/Gathering/BP_RN_Chest.Default__BP_RN_Chest_C:InactiveGroup
Error Failed import for SceneComponent /Game/Blueprints/Gathering/BP_RN_Chest.Default__BP_RN_Chest_C:LootLocations
Which leads me to believe I’m not using the correct way for adding scene components in code. Can anyone help?
Can you temporarily try something other than SceneComponent just to see if it is related to scenecomponent somehow?
**Must Attach to Root Component**
You are not setting the attach parent for these new components it looks like!
```
ActiveGroup->AttachParent = RootComponent;
InactiveGroup->AttachParent = RootComponent;
LootLocations->AttachParent = RootComponent;
```
:)
Rama
You need to add the UPROPERTY keyword to subobjects such as components, or the engine’s management internals will ignore it and blueprints will not be saved with said subobjects. This is what’s happening here – the initial construction goes fine, but when you save your level, the components are lost, leading to these errors when the level is subsequently loaded.
That’s just the very basics. There is a lot you can do with managed properties in the editor, like making them editable so these components don’t always have the same locations. This is done through the VisibleInstanceOnly/VisibleAnywhere/EditInstanceOnly/EditAnywhere property keywords. I won’t go into too much detail as this is just touching the tip of the iceberg and there are lots of examples and tutorials out there to delve in.
cmartel, thanks, that makes perfect sense. I didn’t make them UPROPERTIES because I figured I didn’t need them as variables for event graphs and such, but it makes sense that that also affects saving. Adding UPROPERTY() and recompiling the affected blueprints solved the issue!
UPROPERTY() is NOT just for “variables for event graphs and such” or saving. The main point of UPROPERTY() is to prevent from being garbage collected. UPROPERTY is a part of reflection mechanism in UE.