Download

help| class-level blue print communication

Hello,
I want to create a class of teleport blocks (if the player stand on it, he teleports to a location).
The locations are in the level Blue print, can I send them to the class?

this is the code:

of course it doesn’t compile now (teleport function I created doesn’t receive expected variables),
How can I send data from the level blueprint to the class? is it possible?
if not, how can I create a few instances of this class, where every instance gets different x,z,y values?

How about this:

An actor with a component that indicates teleportation destination:

When the player enters the box, we teleport them.

Place these in the level and drag the component where you need it.

vid: https://i.gyazo.com/1a03241352784389…2abdfe8538.mp4

Would that work?

Yes, thank you(:
but for general knowledge- I can’t send variables to a class from the level blue print? It confuses me because in normal c++ code if I have a function member in a class, and I create an instance of that class I can send variables to that function member

You can, drag the actor’s reference to the LB’s graph, drag a wire, call the function:

thank you so much! I was able to do it.

Not sure if this is the best way to pass level asset data out to the rest of your code, but its a way I’ve found works… In your ‘Game Instance’ create variables to store the asset data you want to make available from your level. In your level select the asset you want access to and in the level blueprint use ‘create reference to’ to make a variable for it, then use the ‘Get Game Instance’ node and drag off its output pin to create a ‘Set [the variable you created of same type]’ and pass it the reference to your level asset. The data you’ve stored in Game Instance should then be accessible from anywhere in your code…

Be interested to see what other people think of this method and if there are any better ways?

Creating hard references in game instance for actors in level blueprints sounds unwise. So what happens when you load level 2? Populate the GI with hundreds of variables only a handful of which aren’t null at a time, depending on which level we’re in?

Bind Event Dispatchers dynamically when the level loads - whatever is in the level can hook up to the necessary functions / events in the framework classes. Works for actors spawned dynamically as well.

And / or, communicate through Interfaces. Use tags and inheritance. [HR][/HR]
tl;dr - use as few hard refences as possible
tl;dr2 - don’t use level blueprints

Note how the teleport is quite happy to work with the Pawn even though no hard references are present and there’s no script in the LB.

Choosing the right communication method will depend on circumstances and who needs to talk to whom.