Initializing a simple class variable?

Hi Farshooter

yes, it would be different. For UObject, if SomeClass inherits from it, you go;

foo = NewObject<SomeClass>();

If its an actor you’d spawn it, and I don’t think you could do that in a constructor…

Lets say that I have a variable foo which is of the type SomeClass* in my header file and I want to initialize it in the constructor of my source file.

How should I go about doing that?

Would it require using NewObject or ConstructObject?

Would the method be different if SomeClass inherited from UObject or AActor?

When would you ever need to use ConstructObject?

Okay. Your answer does help clear up that issue. I have one last question. How do I initialize a class in Unreal that doesn’t inherit from UObject.

Would the following code be acceptable or would you do it differently in Unreal?
SomeClass* foo = new SomeClass();

It’s for deferred execution of the construction;
https://docs.unrealengine.com/latest/INT/API/Runtime/CoreUObject/UObject/ConstructObject/2/index.html

Yes, that’s how you initialize structs. Or often you can cast- to custom game mode, say, from a UGameplayStatics function;

Or initialize a pointer to NULL.
The rest I do in blueprints. Spawning actors for example, I do in bp’s.

Hey Farshooter- dont let me go into the new year with 404 karma… :slight_smile:

Thanks for the help! Your last post really helped to clear up my confusion.