• UE常见变量并且在【细节面板】中进行修改


    1. 在UE4中新建一个C++类:TestActor,继承子Actor ,UE4会自动在类的前面添加上大写字母A,最后生成的类是:ATestActor;
      在这里插入图片描述
    2. 在UE4的内容面板中会出现新建Actor对象
      在这里插入图片描述
      在VS2019编辑器中,会出现对应的类:TestActor.h和TestActor.cpp
      在这里插入图片描述
      TestActor.h
    // Fill out your copyright notice in the Description page of Project Settings.
    
    #pragma once
    
    #include "CoreMinimal.h"
    #include "GameFramework/Actor.h"
    #include "TestActor.generated.h"
    
    UCLASS()
    class FIRSTPROJECT_API ATestActor : public AActor
    {
    	GENERATED_BODY()
    	
    public:	
    	// Sets default values for this actor's properties
    	ATestActor();
    
    protected:
    	// Called when the game starts or when spawned
    	virtual void BeginPlay() override;
    
    public:	
    	// Called every frame
    	virtual void Tick(float DeltaTime) override;
    
    };
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    TestActor.cpp

    // Fill out your copyright notice in the Description page of Project Settings.
    
    
    #include "TestActor.h"
    
    // Sets default values
    ATestActor::ATestActor()
    {
     	// 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;
    
    }
    
    // Called when the game starts or when spawned
    void ATestActor::BeginPlay()
    {
    	Super::BeginPlay();
    	
    }
    
    // Called every frame
    void ATestActor::Tick(float DeltaTime)
    {
    	Super::Tick(DeltaTime);
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    1. 在头文件中添加向量变量FVector,并且添加上蓝图属性
    	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Category="MyVars")
    	FVector initLocation = FVector(0.0, 0.0, 0.0);
    
    • 1
    • 2

    注:
    EditInstanceOnly:只有ATestActor实例化以后才可以编辑
    BlueprintReadWrite:可以在蓝图中读写
    Category:表示属性类别为"MyVar"

    // Fill out your copyright notice in the Description page of Project Settings.
    
    #pragma once
    
    #include "CoreMinimal.h"
    #include "GameFramework/Actor.h"
    #include "TestActor.generated.h"
    
    UCLASS()
    class FIRSTPROJECT_API ATestActor : public AActor
    {
    	GENERATED_BODY()
    	
    public:	
    	// Sets default values for this actor's properties
    	ATestActor();
    
    	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Category="MyVars")
    	FVector initLocation = FVector(0.0, 0.0, 0.0);
    protected:
    	// Called when the game starts or when spawned
    	virtual void BeginPlay() override;
    
    public:	
    	// Called every frame
    	virtual void Tick(float DeltaTime) override;
    
    };
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    4.把新建的TestActor拖拽到场景中,在场景中什么也看不到(之所以看不到是因为没有添加组件),但是可以在世界面板中看到场景中已经有了一个ATestActor的对象实例。并且在细节面板中可以看到,新定义的变量类型“MyVars”
    在这里插入图片描述
    5.添加组件,并且设置组件是在蓝图中随处可见“VisibleAnywhere”,定义类别:“MyMess”

    	UPROPERTY(VisibleAnywhere, Category = "MyMess")
    	UStaticMeshComponent* mess = nullptr;
    
    • 1
    • 2

    在构造函数中需要初始化一个对象

    mess = CreateDefaultSubobject<UStaticMeshComponent>("TestMess");
    
    • 1
    // Fill out your copyright notice in the Description page of Project Settings.
    
    #pragma once
    
    #include "CoreMinimal.h"
    #include "GameFramework/Actor.h"
    #include "TestActor.generated.h"
    
    UCLASS()
    class FIRSTPROJECT_API ATestActor : public AActor
    {
    	GENERATED_BODY()
    	
    public:	
    	// Sets default values for this actor's properties
    	ATestActor();
    
    	UPROPERTY(VisibleAnywhere, Category = "MyMess")
    	UStaticMeshComponent* mess = nullptr;
    
    	UPROPERTY(EditInstanceOnly, BlueprintReadWrite, Category="MyVars")
    	FVector initLocation = FVector(0.0, 0.0, 0.0);
    protected:
    	// Called when the game starts or when spawned
    	virtual void BeginPlay() override;
    
    public:	
    	// Called every frame
    	virtual void Tick(float DeltaTime) override;
    
    };
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    // Fill out your copyright notice in the Description page of Project Settings.
    
    
    #include "TestActor.h"
    
    // Sets default values
    ATestActor::ATestActor()
    {
     	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    	PrimaryActorTick.bCanEverTick = false;
    	mess = CreateDefaultSubobject<UStaticMeshComponent>("TestMess");
    }
    
    // Called when the game starts or when spawned
    void ATestActor::BeginPlay()
    {
    	Super::BeginPlay();
    	SetActorLocation(initLocation);//开始运行的时候,位置调整到当前位置
    }
    
    // Called every frame
    void ATestActor::Tick(float DeltaTime)
    {
    	Super::Tick(DeltaTime);
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    回到UE4Editor中,把内容面板中中TestActor拖动到场景中,可以在细节面板中可以看到对应的组件信息,并且可以选择不同的静态网格体。
    在这里插入图片描述

    aaa

  • 相关阅读:
    代码随想录第35天 | ● 01背包问题,你该了解这些! ● 01背包问题—— 滚动数组 ● 416. 分割等和子集
    关于利用卡诺图快速解决时序电路自启动问题的研究
    TCP三次握手
    中间件安全:Apache Tomcat 文件上传.(CVE-2017-12615)
    举个栗子!Tableau 技巧(259):文本表中省市县数据的灵活逐级下钻「方法一」
    实际经历学来的管理知识(1)
    systemverilog学习 --- 随机化(1)
    抖音API:item_get_video-获取抖音视频详情
    Java 简介
    分布式教程从0到1【1】分布式基础
  • 原文地址:https://blog.csdn.net/wb175208/article/details/127132458