Hello,
MY QUESTION:
How to dynamically allocate memory for UE4 container i.e TArray,
and UCLASS, and USTRUCT? without troubling GC and allow me to manage my own memory.
Where is the best location of free those memory, I am currently override the BeginDestroy();
PS: USTRUCT seems can work with new.
MY intention:
I am making a inventory system, so I build a UCLASS() APlayerInventory from AActor.
Since UPROPERTY does not allow TArray* and FStruct*, and my inventory will contain tons of information. So I am considering using pointers and running my own dynamic allocated memory.
Therefore, I use transitional c++ approach new in constructor, and no compile error and editor crash. I predicatively know it wont work TT
APlayableCharacter::APlayableCharacter()
{
Inventory = new APlayerInventory();
}
APlayerInventory::APlayerInventory()
{
// dynamically allocated a TArray to store our inventory info
InventoryItemInfos = new TArray<FInteractableItemInfo*>();
InventoryItemInfos->Reserve(inventorySize);
}
where FInteractableItemInfo is USTRUCT, that i will use to pass infomation between player controller and UI
Here are the crash reporter message:
Fatal error: [File:D:\Build++UE4+Release-4.15+Compile\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 2538]
UObject() constructor called but it’s not the object that’s currently being constructed with NewObject. Maybe you trying to construct it on the stack which is not supported.
UE4Editor_MannequinVsMaximo_852!APlayerInventory::APlayerInventory() [e:\unreal4\unreal project\mannequinvsmaximo\source\mannequinvsmaximo\playerinventory.cpp:10]
UE4Editor_MannequinVsMaximo_852!APlayableCharacter::APlayableCharacter() [e:\unreal4\unreal project\mannequinvsmaximo\source\mannequinvsmaximo\playablecharacter.cpp:35]
UE4Editor_MannequinVsMaximo_852!InternalConstructor()
FINAL PS:
If anyone knows how to detect memory leak, please enlighten me. I am planing to make some memory trace function.
FINAL FINAL PS:
THANKS IN ADVANCED!!!