No World was found for object pass in to UEngine::GetWorldFromContextObject()

ABaseItem* Item = Cast(ItemClass->GetDefaultObject());

//When I Use Item Function,It Will Error :No World was found for object pass in to UEngine::GetWorldFromContextObject()

Can you show where you put this line?

It seems that you’re calling it before the world constructed or during level transition.

Also it’d be more helpful if you paste the whole error message.

Hello ,

This error report was generated after I used the item

It seems that the warning has nothing to do with the line in your first post.

The “GetWorldFromContextObject” warning is come from this “BaseAxe” object.

As for that Chinese warning I have no idea where it comes from.

The Chinese warning is used to identify whether the UseItem function returns true or false.

This is my baseItem class

269851-2.png

BaseAxe is inherited from BaseItem

269852-3.png

GetItem() Is My ItemClass

struct FItemInventoryProperty
{
	//这个是存储的类
	TSubclassOf<class ABaseItem> ItemClass = NULL;

	//物品的数量
	uint8 ItemAmount : 7;

	//构造函数
	FItemInventoryProperty() {
		NULL, 0;
	}

};


//GetItem	
            inline TSubclassOf<class ABaseItem> GetItem(){
		return InventoryProperty.ItemClass;
		}

After debugging it, I found Cast Is NULL, but I don’t know why it will be empty.

OK so does GetDefaultsObject() return NULL? What does it return?

What does GetItem() return?

Can you rename it to GetItemClass() so it’s clearer for the readers?

Class Default Objects return nullptr when you call GetWorld() on them.