I was having some issues spawning actors for a friends mobile game.
I am just having issue with the actual line of code to spawn an actor. Right now
I am using a few methods to build the vector to spawn the actor with-in some bounds,
however I just cant seem to get the actor to spawn. This method set is supposed to generate
a new actor every three fourths(3/4) of a second. Could anyone show me what I am doing wrong in this line.
AFallingObject* newObject = GetWorld()->SpawnActor<AFallingObject>(GetClass(), newVec, FRotator::ZeroRotator);
I know if should be using a if(world) check, but i was trying to force it.
I think that your problem is GetClass(). You should use GetStaticClass() from the class you want to spawn, so it should be:
AFallingObject* newObject = GetWorld()->SpawnActor<AFallingObject>(AFallingObject::GetStaticClass(), newVec, FRotator::ZeroRotator);
I did some light research on this and came back with not a lot of information on this specific function.
From what I did find, this is from an interface, and it returns a pointer to the class.
This is going to sound slightly noobish, but pointer is something i still struggle with.
I think it should look like this, but I am probably wrong in the cpp side.
UClass * GetStaticClass();
UClass * AFallingObject_Parent::GetStaticClass()
Thanks, for any help.
You shouldn’t have to implement the function yourself, try
Thanks for the reply.
It will come back with an error of:a nonstatic member reference must be relative to a specific object.
Ill do somd digging and let you know if i solve it.
Solved it, I was for somereason thinking it was in the base class and not the stuct for the class.
I need to edit the struct and it should be fine.