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

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.

Related

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

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.

Duplicating ScritableObjects with Values per Script Unity

I am making a Multiplayer Game with MLAPI. The problem is, i have a ability system so every ability get executed over an ScritableObject. The problem is, if i have for example five Players in the scene all Players are referenced to the same ScritableObject. And so when somebody execute a ability. The other players are also doing it.
So my Question is can I duplicate my default ability ScritableObject so that every player has its own abilities ScritableObject but with the same Values as the default ability ScritableObject. I must do that over Script.
I know i could create a new ScritableObject and then make a method who paste my values. But maybe somebody has a better idea??????????
Afaik you can use Instantiate also for cloning ScriptableObject on runtime! Only you can of course not use any component taking more then the original parameter (which makes sense).
And the same way as ScriptableObject.CreateInstance this will of course not create an asset but only a runtime instance.

How to access a material instance variable from a blueprint object in Unreal Engine?

I have a texture material that changes between 2 textures. This change can be controller by a variable. I've made a material instance from this material as well as a blueprint that has an object in it, to which this MI texture is applied to. I was hoping to update the materials variable parameters through the blueprints event tick but I am having difficulties figuring out how to access this parameter.
Would anyone know what has to be done in blueprint to access parameters and change them?
Materials can be accessed in Blueprint by creating a Material Instance and then storing a reference into a variable (if you plan to use it int eh future).
Once you create a Material and define a parameter by giving it a name, create a Material Instance based on that Base Material. This is an asset that allows for quick updates by caching part of the underlying pipeline.
Once you've done so, you'll need to use a CreateDynamicMaterialInstance, store the ootput, set it in the corresponding material slot for the Mesh and then use the SetParameter nodes (Vector, Scalar, etc.).
Once you've done that, you're good to go.
You can also get an Instance from a slot directly if the Base Material is not going to change.

Unreal Engine Blueprint: how to move actor along spline?

In my game there is an Actor implemented in a Blueprint. On each level instance of this actor must move along some path. On different levels the paths are different.
How to implement this behavior?
If I add Spline component to this Blueprint then the path will be identical on all levels. But I need different paths. Maybe there is an ability to add a reference to another actor in the current level? But I cannot find it.
Have you tried this solution? You can always keep actor reference in spline(new spline on each level instance) or create "SplineManager" bp to deal with reference update.

Game: General Structure and Game Item Structure

I am making a graphically simple 3D game in C++ using DirectX. The main problem I am having is with how to structure some things efficiently. Right now I know my goal for certain areas but not how to ideally perform them.
For instance, right now I am storing all meshes and textures in an Asset class with enumerated definitions pointing to each asset. All meshes and textures are loaded when the game starts by creating an Asset object and initializing it. From there I load meshes and textures to objects by assigning the pointer given by the Asset object. Is this the best way to go about this?
A harder topic is that of items. For the sake of argument I am going to say we are dealing with scenery. Right now my scenery needs the following:
A name
A mesh
Textures (optional)
Flags (such as Destructible, Flammable, etc.)
Status (such as Burning, Locked, Cursed, etc.)
Abilities (things the object actually does, such as becoming damaged when burning)
The first 5 things on this list are simply variables. But abilities are bothering me. The first 5 can all exist in one item class. But what I do not know how to do is somehow attach abilities to the object.
For example; I want the object to have the "Fire Nova" ability. At the start of each turn, the object damages anything near it.
For me, this means each object would need a "Trigger_Phase_TurnStart()" or some similarly named method and would then need a new "Fire Nova" class with its own unique action for that trigger and its own extra variables (Damage, Range, etc). So now I have the base object class and a new Fire Nova class that inherits from it.
But now what if I needed an object that has Fire Nova and Frost Nova and also Slowing Aura and other such abilities. Basically I need a way to add triggered effects to an object without needing a new object class for each of them.
So by the end I would be able to have say:
(pseudo code of the object's components)
name = Elemental Orb
mesh = "Mesh_Sphere"
textures[] = "Tex_Ice", "Tex_Fire"
flags = OF_Destructible
status = SF_Cursed | SF_Burning
abilities[] = Fire_Nova, Frost_Nova, Slowing_Aura
And this orb would simply be the object class with all these attributes. The object would then activate each stored ability's trigger at the appropriate turn phase for any actions to perform.
Right now I am thinking I might need to make a class for each ability possessing every turn-phase or action trigger (inherited from a base ability class) and have them perform the appropriate action when the object calls them from it's array of abilities. Would this be the best way to do this?
As a separate issue. Some flags would require additional variables that would otherwise be unnecessary. For example, Destructible would mean the object would have health whereas without the flag it wouldn't need it, or an Openable item would need an array of contents. What would be a good way to ration these variables to when they are needed? I do not need every wall to have health and an empty contents array for example.
Finally. Assuming the bullet-listed attributes above are all an item needs, how might you suggest I best store them? To clarify, I would like to be able to write:
CreateItem(ITEM_CHAIR);
and have this return the created object with name, mesh, textures, flags, status and abilities. What structure might be suitable for achieving such an end effect?
To summarise:
Does my current Asset storage seem feasible?
What is the best way to create abilities to attach to the object class without making numerous separate object classes?
Is there a way to limit the variables (or at least memory usage) when the associated flag is not present?
What structure or format would be best for storing fixed item definitions?
Sorry if this is a little long winded. If you cannot answer all the questions then an answer to one would still be appreciated. Question two is probably the largest priority for me right now.
Thanks for your time :)
I want only answer question 2 and it looks like you need a decorator pattern. In OOP a decorator pattern is useful when you have many ingredients and wants to decorate an object, for example a pizza. Unfortunately you need to create for each ingredient a separate class hence I think you have the right approach. The good thing is that with the decorator pattern you can wrap the object over and over with abilites classes and call only one method at the end to do all the stuff.