Why World Context pin appears on function nodes called inside of Blueprint Function Library? - unreal-engine4

Lately I was creating some global functions inside of Bluprint Function Library (BPFL) and I've noticed that when I call function inside of another function that is also created in same BPFL, World Context Object Reference input pin will appear on the node. This pin doesn't need to be plugged and all the functions will compile without any errors or even warnings.
I've searched for the answear but I wasn't able to find any. I've found only UE-39873 bug ticket which exacly describes this behavior and pull request 8016 that would fix it but It has been resolved as 'Won't fix' without any reason given.
You can even quickly reproduce it by following these steps:
Create blank UE project and open Editor
Create new Blueprint Function Library
Create new function inside of Blueprint Function Library
Call the same function inside of it's own body
World Context Object Reference input pin should appear on function node
(UE5.0.3 / Epic Launcher version)
So my question is:
Why does World Context pin appear in this specific case and what is the purpose of using it?
Thanks in advance for any explanation!

This question has been answered on UnrealEngine Forum
Thats nothing you should worry about (if gives you an error just connect it with the world context variable).
But basicly, every function that comes from a function library (not from an actor), needs to have a reference in the world to be executed. That’s why it appears, when you call a function from a class that comes from the the class actor it will assume that the world context is the actor itself, that’s why it not appears in characters and actors, it still there but it just not visible.
And additionally here:
When function libraries need a reference of the world sometimes for some tasks…
for example get all actors with some tag…the function need to know the world where those actors are…or a delta time, etc.
There is a way to tell the library function to use the actor that is calling it as world context object so the world context pin does not appears in the blueprint node and is adding the meta WordlContext.

Related

Accessibility of main from agent's statechart

May I know if main is accessible to all elements in the model?
The reason I ask is that I have created a simple M/M/n model with one resource type created through ResourcePool. The behaviour of the resource type is implemented using a statechart. I write a simple code in the action of a transition in the statechart, i.e.
if (agent_variable < main.my_parameter) { /* do something */ }
The code does not compile and give an error message "main cannot be resolved to a variable". I cannot figure out why the statechart cannot recognise main.
Thanks
Welcome to SOF, Stephan.
First, always use code-complete (Ctrl+space). You will then see what is and what is not possible to access from where you are. In your case, main would not even be an option :-)
Now, your model root (typically that is main) is always accessible via getModelRootAgent() but you will need to cast it to your Main class, i.e. ((Main)getModelRootAgent())
Otherwise, Main is accessible to all agents that are somehow embedded into Main. This is classic OOP principles. Your Resource agents are not actually an embedded population so no direct access to Main. (You can make that happen in the ResourcePool properties, though)

Node.CloneNode() not a function -dom-to-image.js

I want to create a .png file of a HTML page in angularjs and download it. For this I'm currently using dom-to-image.js and using the domToImage.toBlob function and passing the node element to it. But internally when it goes to dom-to-image.js it throws the error:
node.cloneNode() is not a function
Can anyone please assist me here?
Thanks
This error arises when you attempt to call cloneNode() on anything other than a single DOM node.
In this case, the error is coming from the dom-to-image library, which calls that method internally.
Note that without a code snippet, its hard to identify the precise issue with your code, but the point is, when you call domtoimage.toBlob(), you need to supply a single DOM node.
So double check what you are calling it with. If you are selecting by class, for instance, you could end up with more than one element.
Its best practice to be precise with which node you want to convert to a blob - use the id attribute, like this:
domtoimage.toBlob(document.getElementById('element')).then(...)
where element is the id of your target node.
Its also possible you're selecting with angular.element() or even using jQuery directly.
In both cases, this returns an Object -- which you can't call cloneNode() on.
Also note the following from the Angular docs for angular.element():
Note: All element references in AngularJS are always wrapped with jQuery or jqLite (such as the element argument in a directive's compile / link function). They are never raw DOM references.
Which means you would observe the same behavior in both cases, e.g. both of these:
domtoimage.toBlob($('#element')).then(...)
domtoimage.toBlob(angular.element('#element')).then(...)
would result in the error you see. You can index the Object before supplying it to domtoimage.toBlob(), perhaps like this:
domtoimage.toBlob($('#element')[0]).then(...)
domtoimage.toBlob(angular.element('#element')[0]).then(...)
and that would also work.
Also check out this post about "cloneNode is not a function".

how to access a blueprint component with an Unreal pawn character spawned from the player start set up in the game mode?

I'm kind off a beginner, I was following the tutorial in the unreal documentation for direct blueprint communication, my problem is the following: when I set up a character blueprint so it accesses another blueprint with an object reference I want it so when my character is spawned that instance of my character is able to access the referenced object, currently it generates an error that pretty much says that that particular instance of my character is not the one that has the object reference variable set up, it only lets me assign it to characters in my scene yet these ones aren't the ones that are used to play when I hit play in the editor, the one used to play is set up so it's spawned by the game mode. thought this is probably not the way I would find it very useful to know a workaround to this.
C++
You can use GetComponentsByClass in BeginPlay(), e.g.:
TArray<UActorComponent*> Comps1 =
GetComponentsByClass(UStaticMeshComponent::StaticClass());
Or you can add tags in specified Component, and use GetComponentsByTag:
TArray<UActorComponent*> Comps2 = GetComponentsByTag(UStaticMeshComponent::StaticClass(), FName(TEXT("t1")));
They worked both for Blueprint Component and Native Component.
Blueprint
If there's only one character in level, you can use Get Actor of Class.
If there'are more than one characters, you can use Get All Actors of Class and foreach them.

hierarchy of functions in MatLab

I have been reading someone else's matlab code and I don't know how the code structured. I mean I would like to know the hierarchy of functions, which function uses which function. I am reading the code to figure that out but its taking a lot of time.
So is there any other way I can see this hierarchy without reading the whole thing? To be honest it is starting to get confusing. Maybe MatLab has a built in function for that! I found this:
How can I generate a list of function dependencies in MATLAB?
but this doesn't seem to be helpful!
The MATLAB profiler will show you what functions are called by your code (and much more information to boot) and allow you to click through the hierarchy of function calls. You can either call profile on and then run your code, then call profile off and profile viewer, or you can simply call profile viewer and type a single line of code to run in the edit box at the top.
Use the dependency report provided in MATLAB:
http://www.mathworks.co.uk/help/matlab/matlab_prog/identify-dependencies.html
There are also some tools on the File Exchange, such as fdep.
No idea about a function to show visible or depended-upon functions. However the basic rules are:
1) Only the first function in a .m file (normally has to have the same name as the file itself) is visible outside that file.
2) Any function can see any top level (see 1.) function if the file is in the matlab path. Matlab can show you the path so you know where it's hunting.
3) The order of the path is important, the first instance of a function called foo found in the path will be called. Obviously the current directory is at the top of the path.
3) All functions in a given file can see all other functions in that file.
That's the basics. No doubt there are other rules, and possibly exceptions to this. But that understanding generally serves me well.
Obviously the easiest way to work out which function is being called is to click on it in the editor and open it.
One thing I do is simply place in each function at the beginning fprintf("inside function <name>/n"); and at the end of the function fprintf("leaving function <name>/n"); where <name> is the name of the function.
This will give you a very specific list of which function is being called by which function (based on the order that they appear). Another thing like this would be to place fprintf("function <name1> calling function <name2>/n"); so you can be more explicit about which function is being called by which one.

How does Import and Export work at Runtime in MEF?

I am starting to learn, MEF and one important thing in it is that I can mark some item (class, propety,method) with Export attribute so that, who ever wants use it will create Import attribute on an instance varaible and use it. How does this mapping happen and when does it happen? Is the import happen lazily on demand or all the composition happen at the start up? Sorry for the ignorant question, I am trying to understand the flow.
It happens in a phase called "Composition". First you create a container and load all your possible sources of parts into it, and then you Compose it. When you do the composition, it resolves all the dependencies and throws an exception if it can't resolve them all properly.
In general, your parts get instantiated during composition (and if you set a break point in the constructor of your part classes, you will see the break point hit during your call to Compose()). However, you can override this in a straightforward way if you use Lazy<T> as the type of your import (assuming you exported your part as type T).
To see how the composition works, take a look at the Compose() method here.