How can I expose a property in C++ to blueprint spawn-function?

You have the ability to mark variables in blueprints to be exposed as a pin on spawn-functions.

Is this possible for C++ properties (UPROPERTY(…)) ?

1 Like

Any intel on this?

Hello, I ran into this issue today and was able to resolve it using “Meta=(ExposeOnSpawn=true)”

In my case the code was like so:

UPROPERTY(Replicated, EditAnywhere, BlueprintReadWrite, Meta = (DisplayName = "Caster", ExposeOnSpawn = true), Category = "Magic")
APawn* caster;

Hope that helps :slight_smile:

1 Like

Is there a way to ONLY expose it on spawn? I want to set a class type (TSubclassOf<>) during SpawnActorFromClass (Blueprint) but do not want access to that variable later on.

UPROPERTY(meta = (ExposeOnSpawn = “true”)) brings up LogCompile:Error: Property cannot have ‘ExposeOnSpawn’ with ‘BlueprintVisible’ flag.

I tried some combinations of keywords but did not get it to compile.

You must to put at least BlueprintVisible before to meta flag.

better late than never for an answer, this kind of UPROPERTY should go in public section of the class.
Something like

    	public:
    
    		UPROPERTY(BlueprintReadWrite, Meta = (ExposeOnSpawn = true))
    		int SelectionIndex;

works well where it failed while on private/protected

1 Like