i recently came from Unity engine and i still learn about differences in workflow !
I have created a C++ class of a type Pawn which has a couple of variables of type actor and scene component and i created a BP from that class. This BP has two children of the same type as the variables and i want to load them, to the fields, So i can’t find a way to manually initialize these fields with the child objects. In unity engine you just have fields in the inspector and you simply drag/drop objects to these fields and that’s it !
How you would go about referencing object in UE… it seems to be quite different !
Any tutorial on object referencing in BP and C++ will be also so much appreciated !
SuspRig is variable of the same type that is selected as child actor in the ChildActorComponent;
You want to have a reference to that actor in your variable.
If that’s it, then you get your ChildActorComponent → GetChildActor → Cast it to the class you need → Set the variable with the Cast result.
You can try doing it in the Construction Script or on BeginPlay; However, I’ve just tried doing it in the ConstructionScript and it does set the value to the variable and you can log its name to see that it’s valid, but it’s not shown in the Details, so it may be a little confusing.
I’d personally suggest getting the actor on BeginPlay and printing out an error in case if it fails.
well as far as i understand, initializing references is always done through C++ and Blueprints only and there’s no a way to drag and drop any object to the fields in the inspector as it’s done in Unity engine ? If that’s the case it’s fine, i managed to do it by using the Construction Script as you suggested, i’m just used to drag and drop stuff
Anyway, if i can ask another quick question…
The Suspension rig is a C++ class which inherits the AActor class, i created a BP object based on that C++ class and i created a ChildActorComponent in the main car BP ( which is a pawn ) and i set up this ChildActorComponent to reference the BP_SuspensionRig class. The problem is that the BP_SuspensionRIg doesn’t seem to move with the car even though it is attached as a child… why is this ? Like in Unity engine if you attach an object to another one it always moves with it… Should i do something specific to make it move with it’s parent !?
Depends. If it’s a reference to the library asset, you can. But with the components and such, there’s no UI way to initialize them, as far as I’m concerned.
No, it should move with it just fine. Sometimes there are bugs when components created in c++ are not properly attached, but in general recompiling and restarting the editor helps. And make sure you didn’t select World location here:
The rig actually moves with the car. There’s just a bug or something in the latest v5.0.1 where if i try to alter the position/rotation from Details/Transform, in my case the rig stops follow the parent. That’s why i got confused !