C++ Struct is Having its Data Cleared in Blueprints

your linked list has no logic regarding adding.

Does the add function in the MyLinked list supposed to create a new node then populate it with the passed in structs?

Does it insert as the first element of the linked list or is it injected in the current place?

I’m guessing all of the UNodes are linked to each other via a pointer Next, Though I don’t see any logic to traverse the Linked list.

Theoretical logic:

void UMyLinkedList::Add(const FMyStruct& InStructs)
{
	UNode* n = NewObject<UNode>(this);	
	n->Add(InStructs);

	if (Head == nullptr) {
		Head = n;
	}
	if (Current != nullptr) 
	{
		n->Next = Current->Next;
	Current->Next = n;
	}	
}

I’m not sure how far back unreal will honor the pointer chain. Only the current is probably a UPROPERTY the rest are dangling onto the current.

Edit:

So far I’ve narrowed down the error to you calling NewObject as a default initializer inside of a UPROPERTY. You can’t do that.

Narrowing down the errors…

Also calling

const FMyStruct& GetStruct() const { return Structs[0]; }

in case of the struct not having any positions will cause a nullptr exception.

Narrowed down the problems and caught all of the nullptrs along the way

def.zip (881.2 KB)

UE 5.4

Default values show up correctly in blueprints and can be overridden with a simple function for now just to prove the list is working correctly.

You can only use NewObject once the world is instantiated. You cannot init with it.

1 Like