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"

UStaticMeshComponent->SetCollisionEnabled Access Violation (nullptr)

The problem is the IsTemplate() function called from OnComponentCollisionSettingsChanged() in the static mesh component. Within IsTemplate, it checks the flags of the Outer object, however, the outer object is null. I've confirmed this is due to garbage collection by setting the garbage collection time to 1 second.

I have a Pawn with a UStaticMeshComponent and when the player presses a button, the collision and visibility states of this mesh are toggled. However, after 60 seconds the engine crashes on SetCollisionEnabled with an access violation (null pointer somewhere). The component is a UPROPERTY and the component pointer is valid since SetVisiblity works just fine and is called immediately before SetCollisionEnabled. I can also do MeshComponent->GetBodyInstance()->SetCollisionEnabled without a problem, so it must be something during the physics state checks. 60 seconds is when the garbage collector kicks in, so something is getting garbage collected when it shouldn't be.

Am I missing something or is this a bug? Thanks!

Relevant code (using generic names):
State is a boolean indicating the toggle state.

 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Mesh")
 UStaticMeshComponent* MeshComponent;

 MeshComponent->SetCollisionEnabled(State? ECollisionEnabled::PhysicsOnly : ECollisionEnabled::NoCollision); // Works fine until 60 seconds have passed then it'll crash

I should also add that using SetCollisionEnabled on this particular mesh component causes this warning and I can't find any information on why:

 FBodyInstance::ApplyMaterialToShape_AssumesLocked : PComplexMats is empty - falling back on simple physical material.
Product Version: UE 4.9
more ▼

asked Mar 09 '16 at 12:45 PM in C++ Programming

avatar image

16 1 2 6

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

Turned out this was one of those problems that are caused by something else entirely and through debugging it, you discover and fix the root problem. The problem seemed to be the way I was creating my components in the Pawn's constructor. I was calling RegisterComponent and AttachTo, and it seems that removing RegisterComponent fixed the issue, which actually turned out to be my root component being garbage collected or not being registered properly or something along those lines.

more ▼

answered Mar 09 '16 at 02:21 PM

avatar image

16 1 2 6

(comments are locked)
10|2000 characters needed characters left

short version: I was using a BP made from a C++ class. Calling SetVisibility(...) on subcomponents crashed just like the above. Removing the BP of my class, and using only casts to the real class not BP in my other BPs fixed these sorts of problems.

long version: In case it helps someone, a related problem I had was with a C++ actor class that would randomly crash and had strange behavior. I was creating a root component and 2 subcomponents, and the editor would randomly show more components with different names, and the visual representation it showed in the editor looked like something cached from long ago, and would still show that way even after cleaning out my project (deleting the dir and pulling from git and regenerating files).

In the C++ class, I can toggle visibility of subcomponents, and doing that crashed just like the above. Adding more fields, or changing the order of the fields in the .h file would seem to change the behavior.

But deleting any BP_MyClass in my levels/maps (but not actually deleting BP_MyClass itself) and directly using MyClass in levels/maps fixed the Access violations, other random crashes, huge performance lag when spawning actors, and some other oddities. And also removing casts to BP_MyClass in my blueprints fixed other problems and things I found weird (like it was calling the constructor 4 times, but now only 2 times for one object (but BeginPlay only once)).

And I was never using RegisterComponent or AttachTo, only CreateDefaultSubobject, SetRootComponent and SetupAttachment.

more ▼

answered Jan 15 '18 at 09:06 PM

avatar image

1 1 1

(comments are locked)
10|2000 characters needed characters left
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