Access violation on array of struct pointers

Hi All

I have an array of struct pointers that’s in a header file;

TArray<MyStruct*> MyArray;

As soon as I start trying to use it, I get access violation reading location 0x000000…

Even just calling MyArray.Num(), It crashes the editor. Do I have to do something before using this type of array?

Thanks!

EDIT: This is even happening after I make it an array of structs, and make the array a UPROPERTY. And also comment out any other functions that could be trying to access it.

I think you need to call init first

https://docs.unrealengine.com/latest/INT/API/Runtime/Core/Containers/TArray/Init/1/index.html

I tried that, doesnt work. I think i’ve done something wrong somewhere, the access violation depends on how its accessed. Loading it on start play seems to work fine. thanks- i’ll just step through everything i’ve done with the class.

Would there be a problem if two things tried to access the same array at the same time?

No, I’ll try it…

That shouldn’t be a problem.
It’s a bit lame, but did you try with

MyArray = TArray<MyStruct*>();

I told you it was lame :DD
Usually i have problems with them only if i use the AddUninitialized() method.

I don’t know how to help you, sorry :confused:

Hey zamy, thanks for the suggestion. Unfortunately no dice…

It seems as if you can’t use the player controller to store gameplay data during run time. This array was in a class that inherited from playercontroller. I moved everything to the character classes and it works fine. If anyone knows why this would be or where it’s explained in the docs- please post a comment below, I’d be interested to know. Probably a noob mistake but I’m unclear as to why inheriting from a specific class would make such a basic operation difficult- they both inherit from actor…