Losing const qualifier through soft pointer? Hacky?

Roy Wierer (Seda145)
Sun, 26 Feb 2023 20:32:14 +0000
C++

In a specific situation where I need to access a loaded asset, I could only retrieve a const pointer. Casting away const on a variable and then modifying that variable results in undefined behavior: const_cast conversion - cppreference.com . Instead of const casting I realized I could simply get to the object by first making a soft pointer of the UObject pointer and then getting the asset.

– Hacky? –

	const UObject* A = nullptr;
	TSoftObjectPtr B = TSoftObjectPtr(A);
	UObject* C = B.Get();

5 posts - 2 participants