Issue Spawning Custom Actors

Hello Eveyone,

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.

Thanks,
Paradox

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.
<code>
Header:

UClass * GetStaticClass();

cpp:
UClass * AFallingObject_Parent::GetStaticClass()
{
return AFallingObject_Parent;
}
</code>

Thanks, for any help.

You shouldn’t have to implement the function yourself, try

AFallingObject::GetClass()

instead of

AFallingObject::GetStaticClass()

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.

Thanks,
Para

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.