日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

UE4 C++与蓝图的继承问题

發(fā)布時間:2025/3/18 c/c++ 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UE4 C++与蓝图的继承问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

C++寫了一個類MyChar,并派生了一個藍(lán)圖子類BP_MyCharacter。

// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h" #include "GameFramework/Character.h" #include "MyCharacter.generated.h"using namespace UP; using namespace UF;UCLASS() class CPPTEST_API AMyCharacter : public ACharacter {GENERATED_BODY()public:// Sets default values for this character's propertiesAMyCharacter();protected:// Called when the game starts or when spawnedvirtual void BeginPlay() override;public: // Called every framevirtual void Tick(float DeltaTime) override;// Called to bind functionality to inputvirtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;UPROPERTY(VisibleAnywhere)class UCameraComponent* fpsCamera;};// Fill out your copyright notice in the Description page of Project Settings.#include "MyCharacter.h" #include <Camera/CameraComponent.h>// Sets default values AMyCharacter::AMyCharacter() {// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.PrimaryActorTick.bCanEverTick = true;fpsCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FpsCamera"));//fpsCamera->SetupAttachment(RootComponent);//fpsCamera->SetRelativeLocation(FVector(0, 110, 0));}// Called when the game starts or when spawned void AMyCharacter::BeginPlay() {Super::BeginPlay();auto info = FString::Printf(TEXT("-11mychar,inst:%d"), this);GEngine->AddOnScreenDebugMessage(-1, 21, FColor::Red, info);}// Called every frame void AMyCharacter::Tick(float DeltaTime) {Super::Tick(DeltaTime);}// Called to bind functionality to input void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {Super::SetupPlayerInputComponent(PlayerInputComponent);}

實(shí)驗(yàn)一,做如下操作:

1,修改藍(lán)圖中的fpsCamra的位置,任意,如世界空間位置(0,0,200)

2,注釋掉構(gòu)造函數(shù)中的fpsCamera的創(chuàng)建代碼,并編譯。這時fpsCamera在藍(lán)圖中消失了。

AMyCharacter::AMyCharacter() {// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.PrimaryActorTick.bCanEverTick = true;//fpsCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FpsCamera"));//fpsCamera->SetupAttachment(RootComponent);//fpsCamera->SetRelativeLocation(FVector(0, 110, 0));}

3,恢復(fù)構(gòu)造函數(shù)中的fpsCamera的創(chuàng)建代碼,并編譯,這時fpsCamera在藍(lán)圖中又出現(xiàn)了。但位置被重置為世界空間的(0,0,0)。原因是2,3兩步相當(dāng)于先刪除了相機(jī)組件再新加了一個相機(jī)組件,所有數(shù)據(jù)都是默認(rèn)的了。但如果步2不刪除相機(jī)組件,而僅修改相機(jī)位置,編譯后發(fā)現(xiàn)藍(lán)圖中相機(jī)位置是沒有任何改變的,原因是構(gòu)造函數(shù)執(zhí)行時先執(zhí)行父類構(gòu)造再執(zhí)行藍(lán)圖子類構(gòu)造,這樣C++構(gòu)造函數(shù)中的位置修被藍(lán)圖中的位置修改覆蓋掉了。

這時候資源瀏覽器中BP_MyCharacter并沒有帶星號,也就是說UE編譯器沒有監(jiān)視到藍(lán)圖的數(shù)據(jù)發(fā)生了改變。

AMyCharacter::AMyCharacter() {// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.PrimaryActorTick.bCanEverTick = true;fpsCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FpsCamera"));//fpsCamera->SetupAttachment(RootComponent);//fpsCamera->SetRelativeLocation(FVector(0, 110, 0));}

4,關(guān)閉UE4,不主動保存藍(lán)圖。重新打開UE4,打開BP_MyCharacter,發(fā)現(xiàn)fpsCamera的位置是世界空間的(0,0,200)。而如果關(guān)閉UE4之前,主動保存一下藍(lán)圖,再打開UE4,打開藍(lán)圖,發(fā)現(xiàn)fpsCamera的位置是世界空間的(0,0,0)

總結(jié),此問題的關(guān)鍵三要素是:父類內(nèi)存,子類內(nèi)存,磁盤數(shù)據(jù)。

總結(jié)

以上是生活随笔為你收集整理的UE4 C++与蓝图的继承问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。