Hi All,
C++ noob here. I am fairly well-versed in Unrealscript, but new to C++.
I would appreciate some answers on the following, but first some backstory:
I have created a simple class (header and cpp files) that I would ideally like to extend from Object instead of Actor, as it doesn’t require any physical presence in the world. I require an instance/reference/pointer of/to this class in my custom Character class to handle some calculations.
Coming from Unrealscript, I couldn’t figure out the C++/UE4 equivalent of
var MyObject MyObjectRef;
MyObjectRef = new class'MyObject';
so I extended my class from Actor and used:
MyCharacter.h
UPROPERTY()
AMyObject *MyObjectPointer
MyCharacter.cpp
MyObjectPointer = World->SpawnActor<AMyObject>(AMyObject::StaticClass(), etc);
This seems to work. However, I would like to know:
- How would I go about doing this when extending from Object instead, i.e. declaring the variable and creating a reference/instance of my object in MyCharacter.cpp. Please remember I’m a noob so feel free to be as verbose as possible.
- Is this always how you’d go about spawning actor classes, i.e. working with the pointer to the instance (returned by “SpawnActor”) instead of an actual instance?
Any feedback would be greatly appreciated.