Thank you Daniel
- I tested it and result is the same in both case That’s why I had a question why we need Unit Vector its redundant of code
Thank you Daniel
Daniel why we can’t connect Barrel reference to TankBarrel pointer (in C++) both of class are derived from StaticMashComponent class
In my mind situation is something like:
class A {}; // StaticMashComponent
class B : public A {}; // TankBarrel
class C : public A {}; // Barrel
int main() {
B *b;
C c, *c;
cc = &c;
b = (B *)cc;
return 0;
}
What lecture are you on? What is the type of the function parameter and Barrel?
Lecture is 140 https://www.udemy.com/unrealcourse/learn/v4/t/lecture/5272694?start=0
Later I had backed up my project and tried to Cast down Barrel (in Blueprint) to TankBarrel (in C++) code compiled perfectly, but it didn’t work, because in C++ UTankBarrel *Barrel = nullptr
; Object was not founded and as I guessed TankBarrel can not use Barrel member variables with Cast.
if I am wrong pleas write me?
thank you anyway
No, we’re creating the component in blueprint and then setting the C++ pointer. Going from a pure C++ perspective, it would be akin to this
////Class Constructor////
int* TankBarrel = nullptr;
////Blueprint////
int* Barrel = new int(5);
////SetBarrel Function////
TankBarrel = Barrel;
The fact that TankBarrel was initially nullptr
isn’t exactly relevant to the function that’s setting it.
Also you didn’t answer my question, is the barrel in blueprint UStaticMeshComponent or UTankBarrel
Yes Barrel in bleprint is UStaticMashComponent as UTankBarrel in C++ both of them have same parent class but look I did this:
code compiled perfectly but it didn’t work and I conclude that UTankBarrel can’t use Barrel member variables with Cast? because it is not Ticking (UE_LOG)
That won’t work because whilst UTankBarrel is a UStaticMeshComponent, the opposite isn’t true.
class UStaticMeshComponent
{};
class UTankBarrel : public UStaticMeshComponent
{};
void Example(UTankBarrel* Barrel)
{}
int main()
{
UStaticMeshComponent* SM;
Example(SM); //error
}
That doesn’t work but if it was the other way around it would.
class UStaticMeshComponent
{};
class UTankBarrel : public UStaticMeshComponent
{};
void Example(UStaticMeshComponent* Barrel)
{}
int main()
{
UTankBarrel* SM;
Example(SM); //fine
}
Yes you are right Casting doing nothing but than I did this:
I did not give argument SetBarrelReference() C++ function code compiled and there also could be start game. why I didn’t get Error, because function had not argument ?
Don’t know what you’re saying, sorry.
Sorry if my English is not clear.
we have *SetBarrelReference(UTankBarrel BarrelToSet) functin in C++ which we call from Blueprint and this function require a parameter UTankBarrel pointer, but I did not give it (this is shown in photo) despite of this code compiled and I didn’t get Error. WHY ?
Why are you expecting an error?
because if we call the function which requires argument and I don’t give it program must be crash. it’s syntax error in C++ and this is otherwise in Unreal Editor?
Blueprint equivalent of passing nullptr
ahhh Thank you Daniel