• 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

  • 相关阅读:
    Eviews如何做VAR
    客快物流大数据项目(七十七):使用Impala对kudu更改表属性操作
    图文详解Linux基础经典教程(08)——CentOS安装MySQL数据库
    JavaScript日期库之date-fn.js
    自动泊车的路径动态规划问题研究附Matlab代码
    GBase 8a 部署(centos8)
    Zigbee协议详解:低功耗无线通信的理想选择
    技术对接46
    SpringBoot笔记:SpringBoot集成JWT、Shiro实战
    Drone-Yolo:一种高效的无人机图像目标检测神经网络方法
  • 原文地址:https://blog.csdn.net/wb175208/article/details/127132458