How to Cast local pointer to a global variable? C++

Hi, I want to a cast to global variable of type FStruct how to do this?

What I am trying is:
.h

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Struct")
FMyStruct DatasGlobal;

.cpp

if (FMyStruct* DatasLocal{DT_MyTable->FindRow<FMyStruct >(FName(Name),"")})
	{
		DatasGlobal = DatasLocal;
	}

I got compiler error: No operator "=" matches these operands

Thank You.

bool bValidRow=FCustomThunkTemplates::GetDataTableRowFromName(CastChecked <UDataTable> (CastChecked<UDynamicClass> (AMyClass::StaticClass())
->UsedAssets[0], ECastCheckedType::NullAllowed), Name, DatasLocal);

if(bValidRow)
{
	DatasGlobal  = DatasLocal;
}

Hope it helps

1 Like

Thank You sir for reply, this works perfectly but difficult to understand… :yawning_face:

don’t give up, break it in some small parts and try to learn… you will get it

cheers

2 Likes

.h

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Struct")
FMyStruct DatasGlobal;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Struct")
FMyStruct Something;

.cpp

if (FMyStruct* DatasGlobal{DT_MyTable->FindRow<FMyStruct >(FName(Name),"")})
	{
		/*Now you can do anything with DatasGlobal ... it is already casted dynamically and it will return the already stored datas contained the founded row Name after this cast. Now you can say*/ Something = DatasGlobal->Name; // Now something contains the data founded by DatasGlobal and you can use it anywhere you want globally.

//You can still use DatasGlobal anywhere and you dont't need `Something` but you can have it as wanted.
	}

Hope it helps, cheers!

2 Likes

Thank You sir helping me in my learning progress, I really appreciate it, it was very easy to understand and to the point. :slight_smile:

1 Like