Hey @Dependo. I would suggest you use a different method for spawning an actor. You can use GetWorld()->SpawnActor(YourBlueprintClass, [optional transform, location, rotation, scale])
For the variable YourBlueprintClass you can declare a variable in your .h file like:
UPROPERTY(EditAnywhere)
TSubclassOf<AActor> YourBlueprintClass; // Set up in the editor
// Instead of AActor you can use a more specific class if you want, as long as the blueprint inherits from it
I tried to implement the code you provided but I still get the same error.
I also tried to change the default scene component of the blueprint class, but that only gave me a new error.
What function are you trying to spawn the actor in? Normally you would use FObjectFinder in the constructor, and then call SpawnActor in a function like BeginPlay or Tick. You canât spawn actors in the constructor of a class I donât think.
@zos@kribbeck Thanks for your answerers that help me spot the error.
I created a C++ class from an actor class, in the constructor of the class I set up a TCP socket. In the tick function I launch a new thread if it does not exist, this thread is handling the incoming message from the TCP and it was here I tried to spawn a new actor if I got a specific message. After your answers, I tried to set a bool in the class from that thread. I then added the SpawnActor to the tick function and now it works
So, I think the problem was I tried to call spawn actor outside of the Game Thread
I think itâs not thread-safe to create any UObject (which includes AActors) from a non-game thread (and modifying UObjects in certain ways as well), as the garbage collector runs on the game thread unsyncronized with non-game threads, and I donât think the garbage collector is threadsafe/lockfree. As for getting the callback from your TCP socket onto the game thread, I believe there is a function âdefer into game threadâ or something, where you can pass a functor that will be called later on the game thread.
i get this issue will writing this : GetWorld()->SpawnActor(BPclass, [Location, Rotation, Transform])
i get : C:\Users\slnob\OneDrive\Documents\Unreal Projects\MultiplyOrRelease\Source\MultiplyOrRelease\Spawner.cpp(24) : error C2760: erreur de syntaxe? â)â ?tait inattendu ici; â{â attendu
C:\Users\slnob\OneDrive\Documents\Unreal Projects\MultiplyOrRelease\Source\MultiplyOrRelease\Spawner.cpp(28) : error C2059: erreur de syntaxe? â}â