How should I go about fixing the error "Ensure condition failed: MyOwnerWorld" when cooking my project?

Hello,
I’ve been getting this error when trying to cook my project:

Ensure condition failed: MyOwnerWorld [File:D:\Build++UE4+Release-4.14+Compile\Sync\Engine\Source\Runtime\Engine\Private\Components\ActorComponent.cpp] [Line: 964]

As I understand it comes from ActorComponent’s RegisterComponent() function, but I have no idea which actor or which component could cause this Are there any ways to pin point the causing actor or resolve this error?

Thank you in advance
Andrius

Can you post the entire log please?

Yes, ofcourse.link text

Hey Andriucha,

So what appears to be happening here is the actor that you are adding a component to (or attempting to) does not have a valid world for whatever reason. It could be an issue with order of operations, such as attempting to add the component is taking place before the actor has been initialized in the world.

Here is the code for that ensure:

UWorld* MyOwnerWorld = (MyOwner ? MyOwner->GetWorld() : nullptr);

	if (ensure(MyOwnerWorld))
	{
		RegisterComponentWithWorld(MyOwnerWorld);
	}

Basically it’s checking to see if the owner of the actor component has a valid world, or else it sets the world to null. If the world is null, then the ensure will fail like you’re seeing in your logs. I’d recommend putting some IsValid checks in place (if you’re using blueprints) or making sure to check the validity of the world before spawning any actors or adding any components.

Let me know if you have any further questions.

3 Likes

How can I check in C++ that the world is valid? Or how can I ensure that the world is valid, before I try to add the component?

Hi, I don’t remember exactly what my issue was, but I know I was trying to call some function that needed to have a world reference on an object from inside the constructor. Moving that call to OnBeginPlay() fixed my problem, maybe that can help you too.

I moved the components I made in the constructor to BeginPlay() and they are no showing up in the cook output log. But it still fails with the same error, and this time the entire stack trace is in engine.
link text

I was getting a similar error, because I was calling SetReplicated(true) on an ActorComponent in a constructor. Moved it to BeginPlay and now it compiles when cooking and shipping the solution.