虚幻4 ue4 学习笔记pwan篇 1.1b 创建staticmeshcomponent 静态网格组件

// Fill out your copyright notice in the Description page of Project Settings.

#include "MyPawn.h"
#include "Runtime/Engine/Classes/Components/BoxComponent.h"//    UBoxComponent 引用
#include "Runtime/Engine/Classes/Components/SphereComponent.h"//    USphereComponent 引用
#include "Runtime/CoreUObject/Public/UObject/ConstructorHelpers.h" // ConstructorHelpers 引用
// Sets default values
AMyPawn::AMyPawn()
{
     // Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;
    UStaticMeshComponent* SphereVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualRepresentation"));//无视觉效果
    SphereVisual->SetupAttachment(RootComponent);//添加附件到RootComponent    无视觉效果

    //这里可以用过在ue4 赋值引用得到地址 不是物理路径
    //FObjectFinder是ConstructorHelpers的内部类 
    static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAssetWzh(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere"));//打开素材库

    if (SphereVisualAssetWzh.Succeeded())//判断素材库是否打开
    {
        SphereVisual->SetStaticMesh(SphereVisualAssetWzh.Object);//设置素材 这里有视觉效果
        SphereVisual->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));//设置位置0,0,0为初始位置    初始位置为防止位置 z轴与地平线一致 在根组件没有赋予形状时                                                                                                                      
        SphereVisual->SetWorldScale3D(FVector(0.8f));//SetWorldScale3D 设置组件在世界空间中的变换倍数。 倍数以原来模型大小为基准
    }

}

// Called when the game starts or when spawned
void AMyPawn::BeginPlay()
{
    Super::BeginPlay();
    
}

// Called every frame
void AMyPawn::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
}

// Called to bind functionality to input
void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
    Super::SetupPlayerInputComponent(PlayerInputComponent);

}

 staticmeshcomponent只有视觉效果 没有物理碰撞 需要结合 物体组件例如spherecomponent

转载于:https://www.cnblogs.com/gobai/p/8001682.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值