# How to replicate the variable declared in under the struct?

**URL:** <https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526>\
**Category:** C++\
**Tags:** UE4-20, unreal-engine, UE4, question, CPP\
**Created:** [May 18, 2022, 7:42pm UTC](https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526 "2022-05-18T19:42:50Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 18, 2022, 7:42pm UTC](https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526/1 "2022-05-18T19:42:50Z")

</div>

I have this in the `USTRUCT `under `AItemBase`:

`AItemBase.h`

```auto
USTRUCT(BlueprintType)
struct FMyTestStruct
{
	GENERATED_USTRUCT_BODY()

UPROPERTY(Replicated, EditDefaultsOnly, BlueprintReadOnly, Category = Fashion Items Related)
class USkeletalMesh* SkeletalMesh;

};

```

I am trying to replicate it but It says **AItemBase** has no member **SkeletalMesh**

`AItemBase.cpp`

```auto
void AItemBase::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);
	DOREPLIFETIME(AItemBase, SkeletalMesh);
}

```

How Can I Replicate the variable `SkeletalMesh` ?

---

<div class="post-metadata">

**Author:** ![Arlyn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Arlyn](https://forums.unrealengine.com/u/Arlyn)\
**Post date:** [May 18, 2022, 9:05pm UTC](https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526/2 "2022-05-18T21:05:08Z")

</div>

Hello,

You’d need to replicate the struct variable, not the member of the struct. Replicated `USTRUCT` properties replicate their members if they’re a `UPROPERTY`

Here is a nice resource on structs if you’re not familiar with it: [wiki.unrealengine.com](https://michaeljcole.github.io/wiki.unrealengine.com/Structs,_USTRUCTS(),_UE4_C++_Structs/#Replication)

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 18, 2022, 9:16pm UTC](https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526/3 "2022-05-18T21:16:12Z")

</div>

> [@Arlyn](#):
>
> `USTRUCT`

Thank You for help, so I need to replicate `FST_ItemFashion` ?

```auto
//Fashion Item Struct
USTRUCT(BlueprintType)
struct FST_ItemFashion : public FTableRowBase

```

---

<div class="post-metadata">

**Author:** ![Arlyn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Arlyn](https://forums.unrealengine.com/u/Arlyn)\
**Post date:** [May 18, 2022, 9:21pm UTC](https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526/4 "2022-05-18T21:21:11Z")

</div>

Not the struct directly, but a class member variable of the struct type.

Example:

```auto
USTRUCT(BlueprintType)
struct FST_ItemFashion : public FTableRowBase
{
     UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Fashion Items Related)
    class USkeletalMesh* SkeletalMesh;

}

...(class code)...

protected:

UPROPERTY(Replicated)
FST_ItemFashion ItemFashion;

```

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 18, 2022, 9:27pm UTC](https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526/5 "2022-05-18T21:27:55Z")

</div>

and then how to access the rows? currently I am accessing them like:

`(const FST_ItemFashion* OutRow{ DT_ItemFashion->FindRow<FST_ItemFashion>((ID), "") })`

I will need to do instead?

`(const ItemFashion* OutRow{ DT_ItemFashion->FindRow<FST_ItemFashion>((ID), "") })`

---

<div class="post-metadata">

**Author:** ![Arlyn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Arlyn](https://forums.unrealengine.com/u/Arlyn)\
**Post date:** [May 18, 2022, 9:36pm UTC](https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526/6 "2022-05-18T21:36:44Z")

</div>

I think you’re confusion Structs and Data Tables.

Structs don’t have rows to access like data tables. A struct is just a condensed data _structure_ and data tables have rows of data of the same data structure.

If you want to access a member of a struct you would just do this:

```auto
ItemFashion.SkeletalMesh = nullptr;

```

You can use your custom struct for a data table though. I’m not sure what your use case is here so I’m going to point you to this resource which I’ve found helpful for using data tables in C++: [Unreal Engine C++ Fundamentals – DataTables – Jolly Monster Studio](http://jollymonsterstudio.com/2018/12/08/ue4-c-fundamentals-datatables/)

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 18, 2022, 9:43pm UTC](https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526/7 "2022-05-18T21:43:43Z")

</div>

I have large data tables derived from structs, I create struct in C++ and created data table from it in under editor BP I know very well to use datatables and structs.

I have problem with replicating variables located under the struct.  
SkeletalMesh variable used for attaching the `jacket item` to the sub skeletal mesh of the main mesh.

when I start the game in editor with 2 players , they don’t see each otehr clothing items, in my case they don’t see each others jacket attached to the sub skeletal mesh.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 18, 2022, 9:49pm UTC](https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526/8 "2022-05-18T21:49:54Z")

</div>

You can see in this post how I am working with them.

[forums.unrealengine.com](https://forums.unrealengine.com/t/why-the-dynamic-material-is-always-returning-null-in-switch-case/559514)

---

<div class="post-metadata">

**Author:** ![Arlyn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Arlyn](https://forums.unrealengine.com/u/Arlyn)\
**Post date:** [May 18, 2022, 9:50pm UTC](https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526/9 "2022-05-18T21:50:14Z")

</div>

Sorry - no meaning to offend.

I think the issue may be with how your players are equipping the jacket not necessarily the struct replication. Is the skeletal mesh component of the character replicated? If you equip the skeletal mesh on the server only, the mesh will replicate to the client.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 18, 2022, 9:55pm UTC](https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526/10 "2022-05-18T21:55:02Z")

</div>

Sir, all right, I am just sharing information with you and don’t even think about to be offended 😃

Yes the main bodies can see each other and all the movement/actions are replicated. Only the attached items are not showing between them

---

<div class="post-metadata">

**Author:** ![Arlyn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Arlyn](https://forums.unrealengine.com/u/Arlyn)\
**Post date:** [May 18, 2022, 10:07pm UTC](https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526/11 "2022-05-18T22:07:00Z")

</div>

Great you never know with internet people 🙂

It’s hard to tell without seeing how the items are attached but I think that is where your issue is.

Try adding some checks to make sure only the Server is doing the attaching – something like `if(HasAuthority()=false){return;)`

This will ensure it’s only the sever characters setting the mesh.

Also, logging what is getting attached would be helpful for this as well.

EX:

```auto
if(SkeletalMesh)
{
    UE_LOG(LogTemp,Warning,TEXT("SM name = %s",*SkeletalMesh->GetName()))
}
else
    UE_LOG(LogTemp,Warning,TEXT("SM is null))
}

```

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 18, 2022, 10:14pm UTC](https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526/12 "2022-05-18T22:14:20Z")

</div>

> [@Arlyn](#):
>
> `ItemFashion.SkeletalMesh`

yes, solved… it was actually the client was setting the patterns for skeletal mesh, now at least I found the bug, thank You Sir for help… I will try to fix it

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 18, 2022, 10:18pm UTC](https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526/13 "2022-05-18T22:18:58Z")

</div>

I will try to do something like this.

//.H

```auto
USTRUCT(BlueprintType)
struct FMyTestStruct
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY()
	int32 TestValueClient;

	UPROPERTY()
	int32 TestValueServer;

	FMyTestStruct()
	{}
};

void TestStructReplication();

UFUNCTION(Server, Reliable, WithValidation)
void ServerUpdateStruct();
virtual void ServerUpdateStruct_Implementation();
virtual bool ServerUpdateStruct_Validate();

UPROPERTY(Replicated)
FMyTestStruct TestStruct;

```

//.CPP

```auto
void TestStructReplication()
{
	TestStruct.TestValueClient = 1;
	ServerUpdateStruct();
}

void ServerUpdateStruct_Implementation()
{
	TestStruct.TestValueServer = 2;
}

bool ServerUpdateStruct_Validate()
{
	return true;
}

```

**Results**

Expected if Server replicates changes only

> ClientValue = 1

> ServerValue = 2

Expected If Server replicates entire struct

> ClientValue = 0

> ServerValue = 2

**Actual Result**

> ClientValue = 1

> ServerValue = 2

The server only replicates changes that have been executed on the server and does not replicate changes the client has made locally.

---

<div class="post-metadata">

**Author:** ![lhy1339](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/lhy1339/32/1039839_2.png) [@lhy1339](https://forums.unrealengine.com/u/lhy1339)\
**Post date:** [March 17, 2025, 10:32am UTC](https://forums.unrealengine.com/t/how-to-replicate-the-variable-declared-in-under-the-struct/560526/14 "2025-03-17T10:32:36Z")

</div>

try add UPROPERTY()for your variable,and replicate your struct var like this

```auto
//your_struct.h
USTRUCT(BlueprintType)
struct FMyStruct
{
	GENERATED_BODY()
	
	UPROPERTY()
	float my_float=0.0f;

	UPROPERTY()
	int32 my_int=0;
};

//your_character.h
UPROPERTY(Replicated)
FMyStruct mystruct;

public:
	virtual void GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const override;

//your_character.cpp
void AYourCharacter::GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);
	DOREPLIFETIME(AYourCharacter,mystruct);
}

```

(my english is not good:\<)
