Download

BlueprintImplementableEvent change the variable default value

Hi everyone,
I just encountered a trouble of BlueprintImplementableEvent method. I define the method in c++ like that:

UFUNCTION(BlueprintImplementableEvent, Category = Equipment, meta = (DisplayName = Equip Weapon Finished Notify))|
void K2_EquipWeaponFinishedNotify(class AR_WeaponActor* CurrentWeapon);

And Implement in Blueprint:

I just set the bool variable true, but when I execute at runtime, the variable default value changed, rather than real value ( the real value is still false).

Anyone knows how to solve this problem?
Thank you so much.

I am new to Unreal Engine, Anyone can give me some ideas about this issue?

Can you confirm you aren’t actually calling the K2_EquipWeaponFinishedNotify on the CDO (ClassDefaultObject)? Just add a “Print” and “Self” node and wire “Self” straigth into the String message Parameter of the “Print” node (this should automatically add a “Get Display Name” node between the two. What output do you see when you do that?

The output is that:
image

Could you tell me why this method must be calling on the CDO?
and why this calling will change the variable default value rather than the real value?
Thank you very much.

Could you do that again with GetPathName instead of GetDisplayName?

I’ve put together a quick test:
BP_MyObject posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4 BP_MyObject
BP_MyActor posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4 BP_MyActor::BeginPlay
BP_MyActor::DoSomething posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4 BP_MyActor::DoSomething
With an instance of BP_MyActor placed in the level and the default value of BP_MyObject::bSomeBoolean set to false the log output will be the following when running PIE:

LogBlueprintUserMessages: [BP_MyActor_2] BP_MyObject_C_0 /Temp/UEDPIE_0_Untitled_1.Untitled_1:PersistentLevel.BP_MyActor_2.BP_MyObject_C_0 false
LogBlueprintUserMessages: [BP_MyActor_2] true
LogBlueprintUserMessages: [BP_MyActor_2] Default__BP_MyObject_C /Game/CDOTest/BP_MyObject.Default__BP_MyObject_C false
LogBlueprintUserMessages: [BP_MyActor_2] true
LogBlueprintUserMessages: [BP_MyActor_2] BP_MyObject_C_1 /Temp/UEDPIE_0_Untitled_1.Untitled_1:PersistentLevel.BP_MyActor_2.BP_MyObject_C_1 true
LogBlueprintUserMessages: [BP_MyActor_2] false

As you can see the second instance (assigned to BP_MyActor::InstanceB) will have an initial value of true. This is because previously the ClassDefaultObject also had the function ToggleSomeBoolean called on it which then applies to all instances of the class created afterwards.
NOTE: the GetClassDefaultObject is a non-standard function, but its implementation is really simple:

	/**
	 * returns the class default object for the given InObjectClass in Out_Object
	 */
	UFUNCTION(BlueprintCallable, Category = "Utility", meta = (DeterminesOutputType = "InObjectClass", DynamicOutputParam = "Out_Object"))
	static void GetClassDefaultObject(TSubclassOf<UObject> InObjectClass, UObject* & Out_Object)
	{
		check(InObjectClass);
		Out_Object = InObjectClass->GetDefaultObject();
	}

Opening the BP_MyObject also shows that the new default value is now set to true instead.

The Path name is:
Image_5

It seams be called on CDO directly.
I changed another BlueprintImplementableEvent method, it will not occur this problem :woozy_face:, but I cannot find the difference between the two methods.

You’ll probably need to show the code where you’re calling K2_EquipWeaponFinishedNotify (and any function that calls those functions) or try placing a (conditional) breakpoint in your IDE to figure out where/why it’s called for a CDO.

Could have something to do with instancing where a subobject isn’t actually instanced and remains the CDO. If you access the Outer/Owner of one of these then it might also be a CDO.

I have a NetMulticast method, this method will call K2_EquipWeaponFinishedNotify . Is that cause the problem?

Could you tell me how to solve it? Thanks a lot.