The problem is that when making a Blueprint class based on MapSegment, manipulating the transforms on either the RootSceneComponent or the FloorComponent do not move the static mesh. I’ve ensured that its mobility is set to movable and have tried attaching via AttachToComponent rather than SetupAttachment and providing some attachment rules, but this behaviour does not change. I’ve remade the test blueprint countless times, deleted Binary and Intermediate and rebuilt everything. I’ve also tried to defer the FloorComponent->SetupAttachment call to MapSegment::PostInitializeComponents() but there is still no change.
I can move the transform gizmo within the blueprint editor but the static mesh does not follow it. Ideally, I want the StaticMesh to follow it. It seems as though transforms applied to USceneComponents earlier in the hierarchy are not propagating to children. If I construct the entire thing by hand in blueprint then it seems to work fine, just the C++ side of things is being murky today.
Hello, I’m not 100% sure, but it looks like you are trying to add component to a component (UStaticMeshComponent to UFloorComponent). This is not standard approach in Unreal Engine.
If you want UFloorComponent to have a static mesh, instead of adding sm component to it, make it inherit from UStaticMeshComponent. Then you will have that functionality out of the box and your transform should also work fine.
Yes, that is what I’m trying to do - I’ve seen similar that it is not standard practice, though I’m not sure why that is from a technical perspective. I’ve seen USceneComponents described as being useful “carriers” of other components for grouping them together, perhaps UStaticMeshComponent is just special?
It feels a bit strange to say that my FloorComponent “is a” UStaticMeshComponent that has extra behaviour rather than it “is a” USceneComponent that has a UStaticMeshComponent and other extra behaviour, but if that is considered standard in Unreal…
I see you creating SceneComponent and setting it as the root component, but I do not see where you’re assigning RootComponent before setting up the floor attachment.
If you replace RootComponent in that final line with SceneComponent, does it work?
I thought that the SetRootComponent(SceneComponent) call would handle that. Either way, changing the FloorComponent->SetupAttachment parameter to SceneComponent from RootComponent does not produce any noticeable change neither in behaviour nor hierarchy as viewed in the test blueprint.
Something else I should add while testing this is that the MapSegment’s RootSceneComponent and the FloorComponent both lack Position and Rotation in their transform settings viewed within the blueprint editor. I’m not sure what I broke to get it like that, as I remember looking at this last night and they were there (albeit modifying them did not cause the meshes to move either). A clue possibly?
I believe it does, but I didn’t have the engine code in front of me to check and it felt like low-hanging fruit.
I would not expect the root component to have a transform, fwiw; the root component’s transform is the actor’s transform, after all. The floor and floor mesh, I would expect to have transforms.
At any rate, a very quick implementation of what you describe DOES indeed have the transforms, and works as I would expect…
I feel like you’ve done something somewhere that’s a bit off… but whatever it is, it seems likely to be in the code you didn’t paste in? I’d try starting from scratch with a new test actor, and making sure that works. From there, you could start moving bits across until something breaks?
Many thanks for looking into it. I tried to keep the example minimal but the problem may well be elsewhere. I’ll try going at it from scratch and seeing where it breaks and report back.
I think that in such setup your static mesh component is not treated as normal component in Transform Chain of SceneComponents, because SetupAttachment is meant to be called from Actor’s contructor (not component’s constructor). SceneComponent is like a carrier, but for other Actor’s components - it’s not meant to have it’s own subcomponents.
But I don’t understand why UFloorComponent can’t inherit from UStaticMeshComponent, that feels like an intended way in Unreal. Anyway good luck with what you are trying to do
I’ve played around with it a bit and have some updates.
Packetdancer - I confirmed that the below hierarcy works as expected, using the same structure you provided with all of the attachments set up in a single cpp file, within the Actor constructor:
Actor
-RootSceneComponent
–FirstLevelSceneComponent
—StaticMesh
When splitting the FirstLevel thusly, however:
FirstLevel class:
FirstLevelSceneComponent
-StaticMesh
Actor class:
Actor
-RootSceneComponent
–FirstLevelSceneComponent
it no longer transforms as hoped, in the same way as outlined in the OP.
I suspect this may be to do with the order in which these are constructed, but the fact that the test blueprint shows the hierarchy as expected and only the transforms are broken casts some doubt on this.
Sitiana - the problem I have is that I want two StaticMeshComponents on the FloorComponent. If I use one of them as the base class for the FloorComponent and try to attach another StaticMeshComponent to it, the same problem occurs. It seems really weird having a limit of a single StaticMeshComponent in the hierarchy like this…
Perhaps it would be worth trying again with child actors?