How do I access my variables in a custom WorldSettings?

I’ve tried:

//both return C2039: 'GetMyVar' : is not a member of 'AWorldSettings'

//both return C2275: 'AMyWorldSettings' : illegal use of this type as an expression

but none of them work.

GetWorldSettings() returns a pointer to AWorldSettings, not AMyWorldSettings, which is why the first attempt fails. Your second attempt fails because GetWorldSettings() is not a template function, so your syntax is illegal.

A working approach in this case would be to down cast the pointer you’re getting from GetWorldSettings():


Yup, that does the trick!

I assume I can cast anything with that syntax?

You can use Cast<> to cast anything that is or derives from UObject.

For normal C++ types you can use the standard casting templates.