I’ve been looking for a succinct way to share variables between blueprints using interfaces.
i.e. “BLUEPRINT_B can GET/SET variables declared in BLUEPRINT_A via a Blueprint Interface.”
(The communicating blueprints are not be associated with a visible scene object.)
I have already seen the official Blueprint interface docs and video tutorial but only this post describes exactly what I wanted to do.
In that particular post, the blueprint interface communication works perfectly between the default MyCharacter_blueprint and the Actor_blueprint.
Under the assumption that any blueprint can communicate with any other blueprint I removed the interface implementation from MyCharacter and added it to another blueprint in my project (e.g. a BP_SaveGame).
Unfortunately there is something missing as the communication no longer works and the printed byte value is always zero.
All blueprints can talk to each other, provided that they use that specific interface. You need to go to the blueprint properties and add the interface to it.
I believe so.
The setup is mostly same as described in the [example][1], except that I:
(add) implement the interface in BP_SaveGame instead of his ‘MyCharacter’ blueprint
call the interface from a BP_Hud instead of his ‘Actor’ blueprint
I use an EventReceiveDrawHud in the BP_Hud to trigger the call.
The default value for my byte value is 123 and that is what I expected to print, but it prints 0, suggesting that it can’t see or access the byte variable.
The only thing that is questionable is my GetPlayerController->GetHUD target for the GetByte() interface call.
(See screenshot).
Okay so I see the issue. You are trying to get the Byte from the HUD Blueprint (since you have it as target). But this doesn’t have your BPI interface GetByte function on it. You were suppose to target your BP_SaveGame blueprint, but you can only do that after you’ve created the GameSave object. I’ve provided a sample of retrieving data from the GameMode blueprint using the interface class. This is what I do for global variables as well.
“You are trying to get the Byte from the HUD Blueprint (since you have it as target). But this doesn’t have your BPI interface GetByte function on it.”
Ahh, silly mistake! Makes total sense when you point it out.
“You were suppose to target your BP_SaveGame blueprint, but you can only do that after you’ve created the GameSave object.”
Out of curiosity, I replaced your [GetGameMode] with a mySaveGameObj.
Doesn’t creating an instance of the BP_SaveGamemySaveGameObj variable in my BP_HUD constitute a ‘creation’ (instantiation for use)?
“I’ve provided a sample of retrieving data from the GameMode blueprint using the interface class.”
To your question about SaveGame, yes. By using Create SaveGame Object node to instance your BP_SaveGame variable, you create an object. From there you can interface.
I have created everything very similar to this system and have looked over your example. For some reason my int variable is “not in scope” on my return node on my interface. The variable i am trying to pass is set to public. Do you have a good idea as to why this would be?
Grixis, follow it through and test each step of your implementation as there is probably something missing, mis-connected or an incorrect type. If you still can’t find the error then post a simplified (stripped-down) screenshot of the components in question. A picture says a thousand words!
“By using Create SaveGame Object node to instance your BP_SaveGame variable, you create an object. From there you can interface.”
That works perfectly!
I basically have: Event Receive Draw HUD->CreateSaveGameObject[BP_SaveGame]->GetByte()
For performance reasons, should I set up some kind of branch so CreateSaveGameObject only gets called once by Event Receive Draw HUD (or Event Tick) or does that already happen internally?
Emmm explain me why you getting HUD… where you are in the HUD, also Casting to MyHUD… yet using Interface?
You don’t need to get HUD if you already in HUD, just use function with Target set to “self”
You don’t need to use Interface if you casting, as most people you misunderstanding what Interface is for, it’s not made for communication, it’s made to relate unrelated classed which you can’t cast… yet you casting and using interface You can access functions and events of object by draging and droping object link
Watch my tutorial about basics of objects it might clean your head
Thanks a lot. I have now recently figured out how to do this. I was missing the get all actors of class node. I thought you were to use a target blueprint and get the exact variable. If you find the time i have recently posted a few other questions if your bored.