# How to add StaticMesh to struct?

**URL:** <https://forums.unrealengine.com/t/how-to-add-staticmesh-to-struct/1253825>\
**Category:** C++\
**Tags:** unreal-engine, crash, editor, CPP, Blueprint, question\
**Created:** [August 7, 2023, 7:50pm UTC](https://forums.unrealengine.com/t/how-to-add-staticmesh-to-struct/1253825 "2023-08-07T19:50:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![OftenDeadKanji](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OftenDeadKanji](https://forums.unrealengine.com/u/OftenDeadKanji)\
**Post date:** [August 7, 2023, 7:50pm UTC](https://forums.unrealengine.com/t/how-to-add-staticmesh-to-struct/1253825/1 "2023-08-07T19:50:25Z")

</div>

Hi!

I have a class for player that has an array of my custom struct. I want to add StaticMesh to that struct but I also want to be able to set that struct member in editor (blueprint). Unfortunately, whenever I compile after adding EditAnywhere or BlueprintReadWrite, UE crashes (I’m using 5.0.3).

Here is my struct:

```cpp
USTRUCT(BlueprintType)
struct FWeaponProperties
{
	GENERATED_BODY()
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float TimeBetweenShots;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float CurrentShotCooldown;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		bool bIsHitScan;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float BaseDamagePerShot;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		int32 ClipAmmo;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		int32 LeftAmmo;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		int32 ClipSize;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		int32 MaxAmmo;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		class UStaticMesh* Mesh;
};

```

and here is how that array is declared:

```cpp
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Gameplay")
	TArray<FWeaponProperties> Weapons;

```

My general idea here was to be able to set different types of weapons and with that - each weapon can have different meshes.

What am I doing here wrong?

---

<div class="post-metadata">

**Author:** ![Bojann](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bojann/32/906560_2.png) [@Bojann](https://forums.unrealengine.com/u/Bojann)\
**Post date:** [August 7, 2023, 8:23pm UTC](https://forums.unrealengine.com/t/how-to-add-staticmesh-to-struct/1253825/2 "2023-08-07T20:23:42Z")

</div>

> What am I doing here wrong?

You are using mesh as parameter :). Create Enum for gun types (Gun, Machinegun, Shotgun… etc).

```auto
UENUM(BlueprintType)
enum EWeaponType { Gun, Machinegun, RocketLaucher, Shotgun, BFG };

```

And…

```auto
USTRUCT(BlueprintType)
struct FWeaponProperties
{
	GENERATED_BODY()
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float TimeBetweenShots;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float CurrentShotCooldown;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		bool bIsHitScan;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float BaseDamagePerShot;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		int32 ClipAmmo;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		int32 LeftAmmo;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		int32 ClipSize;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		int32 MaxAmmo;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		TEnumAsByte<EWeaponType> Mesh;
};

```

This should work fine. When struct is read, then just change mesh accordingly.

---

<div class="post-metadata">

**Author:** ![OftenDeadKanji](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OftenDeadKanji](https://forums.unrealengine.com/u/OftenDeadKanji)\
**Post date:** [August 7, 2023, 8:54pm UTC](https://forums.unrealengine.com/t/how-to-add-staticmesh-to-struct/1253825/3 "2023-08-07T20:54:51Z")

</div>

So there is no way to add StaticMesh to structure?

---

<div class="post-metadata">

**Author:** ![Bojann](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bojann/32/906560_2.png) [@Bojann](https://forums.unrealengine.com/u/Bojann)\
**Post date:** [August 7, 2023, 8:58pm UTC](https://forums.unrealengine.com/t/how-to-add-staticmesh-to-struct/1253825/4 "2023-08-07T20:58:25Z")

</div>

Your code works fine for me

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/c/4/ec4192b91ebc727fe47995e0eb0a4babdb7ca55c.png)

---

<div class="post-metadata">

**Author:** ![OftenDeadKanji](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OftenDeadKanji](https://forums.unrealengine.com/u/OftenDeadKanji)\
**Post date:** [August 7, 2023, 9:20pm UTC](https://forums.unrealengine.com/t/how-to-add-staticmesh-to-struct/1253825/5 "2023-08-07T21:20:46Z")

</div>

It seems that the problem is with declaring the array of such structure? I commented that part in my player class and it worked, no crash. But after I removed the comment and the array was back again in that class, ue crashed while compiling.

---

<div class="post-metadata">

**Author:** ![Bojann](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bojann/32/906560_2.png) [@Bojann](https://forums.unrealengine.com/u/Bojann)\
**Post date:** [August 7, 2023, 9:34pm UTC](https://forums.unrealengine.com/t/how-to-add-staticmesh-to-struct/1253825/6 "2023-08-07T21:34:34Z")

</div>

I am not sure, to be honest. But I would still strongly suggest that you enumerate it. StaticMesh is way to complex and there is no need for it. Just identify the mesh using Enumerator.

---

<div class="post-metadata">

**Author:** ![OftenDeadKanji](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@OftenDeadKanji](https://forums.unrealengine.com/u/OftenDeadKanji)\
**Post date:** [August 7, 2023, 9:39pm UTC](https://forums.unrealengine.com/t/how-to-add-staticmesh-to-struct/1253825/7 "2023-08-07T21:39:34Z")

</div>

Yeah, it sounds like a good idea to switch to enum. Thank you for the advice! 😁
