C++ function library plugin startup or something to spawn actor when game starts?

Hi! I am working on a function library plugin and I would like to spawn a custom AActor in the game when starts and then with custom functions make calls to that actor to communicate with the library.

Is it possible or should I think into a different kind of plugin?

1 Like

I’m not sure if I understand it right, but if you want to spawn actor from plugin without being called from the user/dev (just with plugin being enabled), in plugin method StartupModule you can bind FCoreDelegates::OnPostWorldCreation, which should trigger every time a new world is created (= level is loaded), then spawn your actor in the world from there.

Not sure what you mean about the second part. If your actor is native or inherits a native class from your plugin, or if your plugin exposes static BlueprintCallable UFUNCTIONs, then the actor can communicate with the plugin normally like everything else.

2 Likes

im not finding the way for binding it :frowning:

#include "Engine/World.h"
#include "ExtraNodes.h"
#include "ExtraNodesBPLibrary.h"

#define LOCTEXT_NAMESPACE "FExtraNodesModule"

void FExtraNodesModule::StartupModule()

	{
///	   FWorldDelegates::OnPostWorldCreation ..... <---
	}

void FExtraNodesModule::ShutdownModule() { }

#undef LOCTEXT_NAMESPACE
	
IMPLEMENT_MODULE(FExtraNodesModule, ExtraNodes)

how do I bind the function I want to run and where do I define the function?

can you make some simple example with some line like:

GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::White, FString::Printf(TEXT("I am the function running on PostWorldCreation")));

Do you actually need an actor? A world subsystem seems like it would do what you want way easier since the engine will create it for you even if the subsystem is defined in a plugin. I recently did this to create a manager for async save/load operations.

I am learning as much as I can about plugins but I have a lot of blackholes and this library plugin I am doing is very handy for me.

I Use A LOT a basic widget that is a black image covering all the screen with a dumb linear animation and 2 dumb events: fade in and fade out. I store that widget in a variable and when I run the Fadein(float fadeSpeed, FadeColor) event then the widget adds to viewport (Z order 50000 to above in front of everything)_ and fades…

What I want is implement this in my generic function library plugin so I want to have a GENERIC function called fadeIn (and fadeOut) that just creates the widget (or slate) and does everything else…then the fade out will look for that widget (get widget of class?) and then fade it out and remove from parent/ so destroy…

Just a FADE generic function.

I can survive without this lol

Anyway I am pushing myself trying to do this kind of stuff and learn in the proccess.

I’m confused. Why if you need to do something with a widget are you asking about spawning an actor?

Also the Player Camera Manager already has fade functions. You might consider using that instead of rolling it on your own.

sorry for the confusion. My question was general. If I can spawn an actor I would create and add a widget.

Also about camera manager…I try to make my question as generic as possible because I am not tackling a punctual problem. I just want to know how to spawn or create something at start in a library function plugin for general purposes.

BTW…that camera manager sounds interesting but is just not working as it should:

nothing happens

even is not working for me. I saw some youtube videos and it just fades the 3D scene, not widgets in the screen, so a general black widget on top of everything works better for me.

The issue is that solutions need details. For example, the world subsystem (or any of the other types of subsystems) are a great option if you just need to make sure that an object of some kind is created at the proper time. It’s also not a bad option as the hook to then spawn an actor instead of trying to use the PostWorldCreation delegate.

But if you’re trying to spawn a widget at the start of a fade, that is a) not an actor, b) not when the game starts and c) being able to spawn an actor that way doesn’t provide any utility for spawning the widget. It’s like asking a math question about adding when you really want to know about functions.

RE: the camera manager - sorry, I knew it existed and that functionality was there. I don’t know much more than that. Maybe there’s something else you have to setup to use the camera manager, like a custom derived type or something.

So, you want to call a function. That function lives in a plugin. When called, it spawns a widget.

Widget = CreateWidget< >( ... );
Widget->AddToViewport( );

I’ll leave the template and runtime parameters to CreateWidget up to you to figure out where is best to get them (maybe they should be inputs to your function) but this should work just fine.

1 Like

Thanks for all the info! Will bear this and find the best approach for me :slight_smile: