Announcement

Collapse
No announcement yet.

"SourceModels"不是"UStaticMesh"的成员?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    "SourceModels"不是"UStaticMesh"的成员?

    我用代码动态创建了一个StaticMesh, 可以成功的编译和运行,但是我尝试打包的时候提示错误。
    代码如下:
    Code:
    // Fill out your copyright notice in the Description page of Project Settings.
    
    #include "pjStaticMesh.h"
    #include "MyActor.h"
    #include "RawMesh.h"
    
    
    // Sets default values
    AMyActor::AMyActor()
    {
     	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    	PrimaryActorTick.bCanEverTick = true;
    	UStaticMeshComponent* c1 = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMeshComponent1"));
    	UStaticMesh* m1 = NewObject<UStaticMesh>();
    	new (m1->SourceModels) FStaticMeshSourceModel();
    	FStaticMeshSourceModel& SrcModel = m1->SourceModels[0];
    	m1->LightingGuid = FGuid::NewGuid();
    	m1->LightMapResolution = 64;
    	m1->LightMapCoordinateIndex = 1;
    	FRawMesh NewRawMesh;
    	SrcModel.RawMeshBulkData->LoadRawMesh(NewRawMesh);
    	NewRawMesh.FaceMaterialIndices.Add(0);
    	NewRawMesh.FaceMaterialIndices.Add(1);
    	NewRawMesh.FaceSmoothingMasks.AddZeroed(2);
    	NewRawMesh.VertexPositions.Add(FVector(0, 0, 0));
    	NewRawMesh.VertexPositions.Add(FVector(1000, 1000, 0));
    	NewRawMesh.VertexPositions.Add(FVector(1000, 0, 0));
    	NewRawMesh.VertexPositions.Add(FVector(0, 1000, 0));
    	NewRawMesh.VertexPositions.Add(FVector(1000, 1000, 0));
    	NewRawMesh.VertexPositions.Add(FVector(0, 0, 0));
    	//NewRawMesh.WedgeColors.Add(FColor::White);
    	//NewRawMesh.WedgeColors.Add(FColor::Green);
    	//NewRawMesh.WedgeColors.Add(FColor::Red);
    	//NewRawMesh.WedgeColors.Add(FColor::Blue);
    	//NewRawMesh.WedgeColors.Add(FColor::Green);
    	//NewRawMesh.WedgeColors.Add(FColor::White);
    	NewRawMesh.WedgeIndices.Add(0);
    	NewRawMesh.WedgeIndices.Add(1);
    	NewRawMesh.WedgeIndices.Add(2);
    	NewRawMesh.WedgeIndices.Add(3);
    	NewRawMesh.WedgeIndices.Add(4);
    	NewRawMesh.WedgeIndices.Add(5);
    	NewRawMesh.WedgeTexCoords[0].Add(FVector2D(0, 0));
    	NewRawMesh.WedgeTexCoords[0].Add(FVector2D(10, 10));
    	NewRawMesh.WedgeTexCoords[0].Add(FVector2D(10, 0));
    	NewRawMesh.WedgeTexCoords[0].Add(FVector2D(0, 10));
    	NewRawMesh.WedgeTexCoords[0].Add(FVector2D(10, 10));
    	NewRawMesh.WedgeTexCoords[0].Add(FVector2D(0, 0));
    	//NewRawMesh.WedgeTangentX.AddZeroed(6);
    	//NewRawMesh.WedgeTangentY.AddZeroed(6);
    	//NewRawMesh.WedgeTangentZ.AddZeroed(6);
    	//NewRawMesh.WedgeTangentZ.Add(FVector(0, 0, 1));
    	//NewRawMesh.WedgeTangentZ.Add(FVector(0, 0, 1));
    	//NewRawMesh.WedgeTangentZ.Add(FVector(0, 0, 1));
    	//NewRawMesh.WedgeTangentZ.Add(FVector(0, 0, 1));
    	//NewRawMesh.WedgeTangentZ.Add(FVector(0, 0, 1));
    	//NewRawMesh.WedgeTangentZ.Add(FVector(0, 0, 1));
    	SrcModel.RawMeshBulkData->SaveRawMesh(NewRawMesh);
    	static ConstructorHelpers::FObjectFinder<UMaterial> mat1(TEXT("/Game/StarterContent/Materials/M_Brick_Clay_New.M_Brick_Clay_New"));
    	if (mat1.Succeeded())
    	{
    		m1->Materials.Add(mat1.Object);
    	}
    	static ConstructorHelpers::FObjectFinder<UMaterial> mat2(TEXT("/Game/StarterContent/Materials/M_CobbleStone_Rough.M_CobbleStone_Rough"));
    	if (mat2.Succeeded())
    	{
    		m1->Materials.Add(mat2.Object);
    	}
    
    	TArray<FText> BuildErrors;
    	m1->Build(false, &BuildErrors);
    
    	c1->SetStaticMesh(m1);
    	c1->SetRelativeLocation(FVector(0.0f, 0.0f, -40.0f));
    	c1->SetWorldScale3D(FVector(1.f));
    }
    
    // Called when the game starts or when spawned
    void AMyActor::BeginPlay()
    {
    	Super::BeginPlay();
    	
    }
    
    // Called every frame
    void AMyActor::Tick( float DeltaTime )
    {
    	Super::Tick( DeltaTime );
    
    }
    运行效果如下:
    Click image for larger version

Name:	1.png
Views:	2
Size:	385.8 KB
ID:	1164756
    错误提示如下:
    Click image for larger version

Name:	2.png
Views:	1
Size:	12.3 KB
ID:	1164757

    请问有人遇到过类似的问题吗?要怎么解决?
Working...
X