This seems like an extra, unnecessary step to me, but I’m coming from Unity. Is there a way to forgo setting the variable(MyCamera) in the construction script and set it to a CameraComponent directly in the editor?
The CameraComponent is just an example. I’d like to be able to do this with components in general.
Not sure there’s a way to directly set a variable with a component. I’ve never been able to do that. If you’re in a BP, you already have FMJCamera. No need for a variable. If you want to access it from C++, this is what I’m using:
If you need a specific instance, you can iterate over them and check the name with Cameras[i]->GetName(Name).
Note I’m using PostInitializeComponents() because when I packaged my game as standalone, I found out that construction scripts in BP and OnConstruction() in C++ only get called when spawned. If the actor is already in the level when the level gets loaded, construction scripts and OnConstruction() do not get called in a standalone package. In the editor, it always seems to get called.
IMPORTANT: Use BeginPlay event instead of Construction Script unless you know that the actor won’t be in the level when it is loaded.
Thanks for the tip on the construction script not being called. That seems insane to me, but like I said, I’m coming from Unity.
I’ll probably make a setup function that sets a bool: IsSetup? (and does nothing if it’s true). Then call that from both the ConstructionScript and BeginPlay.
If you put it in BeginPlay, it should be fine for all cases. You shouldn’t need a boolean. Just take your two nodes and cut & paste them to the BeginPlay node in your normal event graph.
I agree with you. There should be a way to assign it. You CAN bind widgets to C++ properties though with “meta = (BindWidget)” without quotes in your UPROPERTY. The property name must be identical to the widget name. Nothing else needs to be done. That widget can now be used in C++.
And yeah, the construction thing is weird. It certainly caught me by surprise. Also, it runs BEFORE the components are ready in a standalone game. The order changes. So you can’t even use your BP in standalone because the component isn’t even created yet. BeginPlay is the last thing to execute, so I’d put it there and it always executes.
Here’s a chart explaining the order. Note how OnConstruction is NOT there when loading an actor in a level. One thing that’s missing in that chart is that if you play in the editor, OnConstruction IS called. OnConstruction is called when a property changes so you can update the state of your actor. It’s really mostly an in-editor thing.
Sorry for the long reply. Just wanted to give you some info I wish I had when I started UE.