Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use std::vector in Unreal Engine

I have an issue with using STL features with my UE4 project.

Intellisense is showing an error with its red line and isn't understanding what I'm attempting to write.

I use VS 2017 and have also downloaded the Unreal development settings.

I've tested the STL features with a blank project using the same IDE and it works fine there with no intellisense issues.

I assume that I'm missing some kind of special setting to do with Unreal Engine but I have no idea what it is and can't seem to find anything in their documentation.

Thanks

#include <vector>

#include "CoreMinimal.h"
#include "Interactable.h"
#include "Hand.generated.h"

class Card;

UCLASS()
class SKYLINE_API AHand : public AInteractable
{
    GENERATED_BODY()

public:

    void PlayCard();
    void DiscardCard();

private:

    std::vector<Card*> m_vpCards;

};
like image 705
jckTol Avatar asked Oct 17 '25 17:10

jckTol


1 Answers

Unreal Engine uses its own data structure rather than standard template library for compatibility and portability reason. Check this post by Kaiserludi for the detailed reasoning: https://forums.unrealengine.com/development-discussion/c-gameplay-programming/46700-why-doesn-t-ue-utilize-stl-containers

For vector you should use TArray: https://api.unrealengine.com/INT/API/Runtime/Core/Containers/TArray/index.html

Also when declaring fields of type not directly from Unreal Source, you should always declare them UPROPERTY() or else the engine with garbage collect its memory without you even knowing.

If you want to really use std::vector, someone by the name feixuwu utilized it on his/her websocket. You can check out the code here: https://github.com/feixuwu/UEWebsocket

like image 155
Lee Seoung Yeon Avatar answered Oct 19 '25 07:10

Lee Seoung Yeon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!