Initialize mesh after spawning the actor, collision function vanishes

Dear Community, Happy holiday season! During the holiday, i met a lot of questions and got stuck. I’m hoping someone could give me some tips as soon as possible. I am trying to use this to build my own meshes dynamically, and i posted a question about collision the question link few days before. I got no reply because it’s holiday anyway, but here comes another problem.
When i construct my mesh in the Actor construction function, the collision works. But when i read mesh data after the actor is spawned in my own gameMode class, the collision works no more. To be detailed, i wrote the function in two ways as below:

GameGeneratedActor.h :

UCLASS()

class CPLPL_DRAWWALL_API AGameGeneratedActor : public AActor

{

GENERATED_BODY()	

public:

    UGeneratedMeshComponent* mesh;             //my own mesh

    AGameGeneratedActor();

void initialize(const FString& xmlFilePath);    //the function where i load and create mesh

}

Method 1:

GameGeneratedActor.cpp :

AGameGeneratedActor::AGameGeneratedActor()
{

mesh = CreateDefaultSubobject<UGeneratedMeshComponent>(TEXT("ProceduralLathe"));

    initialize(TEXT("F://xxx.xml"));

}

MyGameMode.cpp :

void AMyGameMode::BeginPlay()

{

Super::BeginPlay();

UWorld* const World = GetWorld();

if (World)
{
	AGameGeneratedActor* myActor=World>SpawnActor<AGameGeneratedActor(AGameGeneratedActor::StaticClass());
    }

}

Method 2:

GameGeneratedActor.cpp :

AGameGeneratedActor::AGameGeneratedActor()

{

mesh = CreateDefaultSubobject<UGeneratedMeshComponent>(TEXT("ProceduralLathe"));

}

MyGameMode.cpp :

void AMyGameMode::BeginPlay()

{

Super::BeginPlay();

UWorld* const World = GetWorld();

if (World)

{

	AGameGeneratedActor* myActor = World->SpawnActor<AGameGeneratedActor>(AGameGeneratedActor::StaticClass());

	myActor->initialize(TEXT("F://xxx.xml"));

     }

}

Now, when i use method 1 to create a room, the player can’t walk through the walls, while i use method 2, the collision works no more. I want to change the file path in the next project. So i want to apply method 2 instead of hardcoding the filepath. But now i’m stuck.

Could you post the contents of AGameGeneratedActor::initialize. I’m thinking that is where the culprit will be.

Sure, of course. The initialize function is:

void AGameGeneratedActor::Initialize(const FString& XmlFilePath)

{

UMaterial *material = Cast<UMaterial>(StaticLoadObject(UMaterial::StaticClass(), NULL, TEXT("/Game/Materials/M_Basic_Wall.M_Basic_Wall")));

material->TwoSided = true;

UMaterialInstanceDynamic* MaterialInstanceDynamic = UMaterialInstanceDynamic::Create(material, ActorMesh);

ActorMesh->SetMaterial(0, material);

XmlLoader = new XMLLoader();

bool result = XmlLoader->LoadXMLFile(XmlFilePath);

TArray<FGeneratedMeshTriangle> triangles;

CreateARoom(*XmlLoader, triangles);  //Add triangles according to XmlLoader's mesh

}