I’m having an issue with setting a boolean variable (CamOnline) to true after picking up an item (a BP_Camera) in my game, and I’m not sure where the issue lies. Here’s a rundown of my setup:
I’m working in Third PersonCharacter_BP, where pressing a key (currently set to Q) calls the Useltem function.
Useltem retrieves item info from the current inventory index, and if it’s a BP Camera, I use GetAllActorsOfClass to get the BP_Camera actor (I only have one camera in the game).
The returned BP Camera is assigned to a variable called CamReference, which I then use to execute the UseCam function, setting CamOnline (a boolean in BP Camera) to true.
For debugging, BP Camera simply prints the value of CamOnline every tick, but as soon as I pick up the camera, this stops printing, and CamOnline never changes to true.
A quick note on my item setup:
BP Camera is a child of BP ItemMaster, which contains overlap logic with OnComponentBeginOverlap and a pickup mechanic.
When the player presses an "Interact key, it calls PickupltemEvent in Third PersonCharacter_BP, adds the item info to an inventory array, and then destroys the item actor.
I’m not sure if the issue lies in how I’m referencing or using BP Camera after pickup. I’ve tried using BPIs, and Casting but I just can’t figure it out.
Any insights would be really helpful! I’ve attached screenshots and linked a video demonstrating the problem.
You appear to be destroying the camera when you interact with it (BP_ItemMaster → IA_Interact).
Edit: Oops, welcome to the forum! Forgive my terse response, but I believe that is why your debug printing stops, actor is destroyed. The way forward is not entirely clear to me, don’t destroy the camera if you intend to use it later is perhaps obvious but I am not entirely sure how this is intended to work or if leaving the interactable item in place will cause other issues.
Hey, thanks for the response, but if destroying the actor is the reason for this, then shouldn’t just getting AllActorsOfClass at index 1 solve it? But sure enough, accessing index 1 doesn’t solve it either.
Also, the same actor is spawned again later (BP_Camera), and so shouldn’t it keep printing since it’s in the event tick of the blueprint item and not just specific to the original camera item. Unless the AttachToComponent node doesn’t actually respawn the item as an actor?
No. It has been destroyed, what on earth makes you think you will now be able to find it at a different index of array returned by Get All Actors of Class? It wont be in that array at all, it’s gone.
The printing should start again I would think, but being a new actor it will have CamOnline false (I presume that is the default value). You are not recreating the one you just destroyed, you are creating a new one, any modifications to the original are gone when you destroy it.
Any references you had to the original are now invalid, they will absolutely not be updated automatically when you spawn a new one.
Being in an actor-component might be effecting the tick, I am not sure on that sorry.
As it is in a component I’m not sure Get All Actors of Class will find it, if you want to get it when it is attached to the player this way, use Get Component by Class.
This is my BP logic for equipping an item, I probably should have attached this screenshot earlier. Weapon is a static mesh component under my character’s mesh.
I believe this might be where the problem lies, and I might just get an earful but am open for suggestions…
Much confusion here, which I have unfortunately contributed significantly too by not asking pertinent questions and making a nonsensical (at least, partially) post last night (I really shouldn’t post at night).
Re-reading your first post, the problem is clearly with where the CamOnline flag is, you are destroying the camera actor when it is picked up so that is not going to work. You indicated it is respawned after, but I am not sure that is so; is it? and if so where is this happening?
As things stand, when you pick up, you get some details from the actor and put them in a struct; which lives in an array of such structs representing the players inventory. Then the actor is destroyed, so all you have is the struct when you equip or use the item. I don’t know what Cam Online is used for exactly, so this may not make sense, but you would need to move this flag into the character.
What is the CamOnline flag used for? Does it really need to be on the camera? The camera which only exists in the world before being picked up, if I am understanding things right, which I may well not be (again)!
Earlier, I stated that the Camera was respawned, this however is not true. I thought that the actor was respawned when the AttachToComponent node was used but rereading the blueprints, it’s obvious that only the Mesh is spawned in and attached and not the whole Actor.
Sorry, I should have been more careful when writing but I was busy with school, and never bothered rechecking the blueprints.
* CamOnline: *
The CamOnline variable is basically just used to SetSimulatePhysics = True on the Camera actor, and then it’s used to cast a few line traces per EventTick, and check whether or not any of the line traces hit the “Enemy”, and if it did then just casts to the “Enemy” to execute some logic therein.
Hope this makes a little more sense, and I suppose the issue is that the Actor is obviously never actually respawned.
Would it be suitable a solution to DettachComponent, and then spawn an actor of class BP_Camera at the player’s location?
Once again, sorry for the headache, am still learning the engine, and lately haven’t been able to put in much time into it because of other matters. But thank you a lot for helping me understand the problem.
No worries, it’s complicated stuff, there will be confusion
I can offer two suggestions, but I can’t say which is better (if either) or if something else might be still better for your particular use case.
Option 1: Don’t destroy the actor and create a static mesh component, instead just attach the camera actor to the player. This keeps your camera actor in the world and what you have/had already should then work.
Option 2: Move all the camera logic into the character. Not sure where you are tracing from and how different that will be from characters position, I imagine to be useful the camera would need to be away from the player somewhere (like, on a stick so they can poke it around corners without getting shot/spotted/whatever), so this maybe isn’t a good option.
I still don’t really understand what you are trying to accomplish, why do you want to simulate physics on the camera when it is in use? Begin attached to the player at that point, this doesn’t really gel.
I decided to settle on destroying the actor then respawning it later, when it’s needed.
The Camera is basically used to detect if an “enemy” is near it, and if there is one in its line of sight, it calls a BPI function named DisableAIMovement.
Currently, this system doesn’t really work because the DisableAIMovement is overwritten by the player casting EnableAIMovement at the same time because the player isn’t looking at the “enemy”.
(Basically, the enemies aren’t supposed to move as long as you or the camera is looking at them).
The reason I enable Physics on the camera is to make it fall to the ground under the force of gravity (rotation is locked on the camera).
I suppose, i’ve already gotten the answer to my original question, and now we’re deviating from the topic. So I should probably create another forum post for that.