Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Access Violation on TArray::Add in actor component

I get this error when I start the game in the editor

Access violation - code c0000005 (first/second chance not available) UE4Editor_SwordTest_5676!UPlayerActionComponent::AddAction() [e:_unreal_projects\swordtest\source\swordtest\playeractioncomponent.cpp:22] UE4Editor_SwordTest_5676!APlayerCharacter::BeginPlay() [e:_unreal_projects\swordtest\source\swordtest\characters\playercharacter.cpp:86] UE4Editor_Engine!AActor::DispatchBeginPlay() [d:\build++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\actor.cpp:3160]

Here's the relevant code

 // PlayerCharacter.h
 UPlayerActionComponent* ActionComponent;

 // PlayerCharacter.cpp 
 // APlayerCharacter::APlayerCharacter()
 ActionComponent = CreateDefaultSubobject<UPlayerActionComponent>(
 // APlayerCharacter::BeginPlay()

 // PlayerActionComponent.h
 TArray<int> MyArray;

 // PlayerActionComponent.cpp UPlayerActionComponent::AddAction

It doesn't only crash on Add, but also Empty, Num, even assigning a new array MyArray = TArray<int>(). I've gotten this error many times now, on different classes using TArray or TMap, so I must be doing something consistently wrong but I can't figure out what. I feel like it just comes and goes. For example it was working fine, then I restarted the editor, got this message

alt text

and now it crashes again after recompiling even though I didn't change the code.

Product Version: UE 4.18
untitled.jpg (38.8 kB)
more ▼

asked Jan 21 '18 at 03:22 AM in C++ Programming

avatar image

3 1 3

avatar image esaberia Jan 21 '18 at 02:13 PM

I just noticed that IsValid(ActionComponent) returns false soon after creation, I am guessing it is being garbage collected? But I don't know why.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hey there if you do it as a local variable in the playercharacter constructor, does it still happen?

more ▼

answered Jan 21 '18 at 11:28 AM

avatar image

6k 161 129 304

avatar image xlar8or Jan 21 '18 at 09:43 PM

The UPROPERTY on the component should prevent it from being GC'd, try adding something more like BlueprintReadOnly, Category = "Test".

avatar image esaberia Jan 21 '18 at 10:05 PM

I've tried many combinations now and I don't see the error anymore, however I can't be quite sure what caused it in the first place.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question