I have created a graph (derived from AActor) class where I want to store all of the graph nodes. The graph has a box component where every node should be attached to. In addition to that I have created a node class which is also derived from AActor. Now I want to spawn the nodes corresponding to the boxcomponent width and depth and saving them in an array inside the graph class. But where/how could I actually attach those actors to my box component ?
If I understand it correctly why don’t you create some “node holders” on your box component and spawn your nodes giving them the location/rotation of those holders you have?, like having sockets on a mesh and attaching something to it?
Also AttachRootComponentTo I believe it only works for skeletal meshes, so in this case you just have to either find a way to create a socket on the box component (I have no clue whether this is possible) or set the location of the nodes on the box.
Okay, well I have corrected my question. I forgot about the fact I am actually want to attach the node to the box component. My fault. But I have tried it with AttachRootComponentTo, everything compiles correctly but the editor is crashing. I am using this code:
I believe abstract default subobjects are null in the constructor until you actually provide a class in a subclass. So the pointer returned from that function is null. Then you’re dereferencing a null pointer. maybe
Okay so I have also tried your method but it also crashed my editor My code I was using :
FVector boxSize = this->nodeContainer->GetScaledBoxExtent();
UChildActorComponent* tempNodeKeaper = CreateAbstractDefaultSubobject(TEXT(“nodeKeaper”));
ANode* tempNode = CreateAbstractDefaultSubobject(TEXT(“node”));
Cast of Graph /Script/MyProject2.Default__Graph to Level failed this is the only showed error I have also commented out everything except this line: ANode* tempNode = CreateAbstractDefaultSubobject(TEXT("node")); so my node class creates this error. Mh and when I set a breakpoint it seems to inintialized correctly: tempNode = 0x000001da58d61000 {neighbours={AllocatorInstance={Data=0x0000000000000000 } ArrayNum=0 ArrayMax=...} ...}.
I have found the setChildActorComponent(TSubClassOf(AActor)) method on the UChildActorComponent. But I cant really find how I could use setChildActorComponent(new ANode()); is wrong