But now, when only BC-A is on the level, and BC-B will spawn only after game start, I can’t set BC-B as a Target in BC-A details, so I can’t access the variable of BC-B.
so bc-a spawns bc-b ? than save the output of your spawnActorByClass and from this you cann access the variables of B. if bc-b is not spawned by bc-a - there is always getAllActorsOfClass
BC-B is not spawned by BC-A, so I’m trying to use get getAllActorsOfClass.
But next problem I have, is that I’m actually have two BC copies of BC-B which are spawn on the level after start, and I need to handle them separately (in fact there 2 players, and I need to get variable from first or second BC depending from who is currently playing).
The issue is that I have an array, and in tutorials its recommended to use “ForEachLoop” to get an array, but I don’t understand how do I get an access to elements of the array separately?
Here what do I have, and I always get here as a result second of two BC-B, and I never get a first one. Maybe I can stop the loop somehow after geting first element and then continue it after some condition?
ok, then maybe two steps back. what exactly are you trying to archive? how are the 2 B BPs spawned? foreach: you have a execute pin loopBody - this needs to be connected, as whatever hangs in that line is executed for EVERY element of the array you’ve plugged in. also doing this with getAllActors on beginPlay is not a good idead, because you can’t control the order of which actor is spawned when - so there is a chance to miss the B BPs. so I guess your playerCharacter should read information of BP B? Then you could jump on to the horse from its back: your BP Bs register themself at your playerCharacter. also not very elegant, this could do the trick. but best would be if you take the time and describe your setup and what you try to archive. cheers
I have a blueprint class, let’s call it BP-B, in which I have a logic for a ball, which could be stretched and launched, so it’s behaves in the way similar to the bird from Angry Birds
In PlayerCharacter (which I call BP-A here) I have a blueprint which describes a Camera behaviour. This camera is waiting until player will stretch and launch the ball, and in a second after I release it, it starts to follow this ball. So that’s why I need BP-A to read a variable (or position) from BP-B, to make camera to move to this direction
And till this moment evrything kinda worked, while I had only one BP-B placed on level, so it was easy to communicate with it.
Then I decided to make BP-B to spawn on level start, and spawn 2 of them, because later I want to make them controled by different players.
So,
I have 2 default player starts on the level
In GameMode I have a function which spawns BP-B in these 2 player starts
Now I have a getAllActorsOfClass in BP-A, which turns to me only the coordinates from the second spawned BP-B
kind of clear sorry, so what’s the job of your playerCharacter? Do you also controll him? if not why is not your ball the playerPawn? have you looked in the node setViewTargetWithBlend? It comes out of playerController and you can pass in an actor which the camera sets as new target (with lerp functions and so on). so when your GM spawns the two Balls, it can save the return of the spawn to a variable (array or two different variables), right? if you want to access that one from your playerCharacter for example (or think about playerController), you can simply use getGameMode node and from that, cast it to YOUR gamemode, and from there your variables are available. but I still have the filling I miss the point
I see that your message was lost, because I got it in email, but it’s not shown here, so I dublicate it and will try to answer.
kind of clear sorry, so what’s the job of your playerCharacter? Do you also controll him? if not why is not your ball the playerPawn? have you looked in the node setViewTargetWithBlend? It comes out of playerController and you can pass in an actor which the camera sets as new target (with lerp functions and so on). so when your GM spawns the two Balls, it can save the return of the spawn to a variable, right? if you want to access that one from your playerCharacter for example (or think about playerController), you can simply use getGameMode node and from that, cast it to YOUR gamemode, and from there your variables are available. but I still have the filling I miss the point
I have no any specific reason to not making a ball as a playerPawn, I’m just a newbie in programming, so I was just making by easiest way I could
However now I understand that using Pawn makes it easier to cast to it, because we can define his parent. So, I’ve made my ball BP as a Pawn, but it bring the ball to weird behaviour. On gif below you can see the diffrence (the right one is not pawn and behaves correct, the left one is pawn and behaves not correct):
What might be the reason of such behavior? It looks like it’s related to physics, but physics settings of balls and applied power to them in both cases identical.
sorry was quite late yesterday. yes, if you have one ball per player you could make it also a pawn and possess it. you can’t possess non pawn (inherited) actors. do you come form unity? your BPs look so in the on you sent me I would suggest: remove the char+sphere from level, add a variable for sphereRef in your character, after you spawn your spheres, get your char and update that reference. then you can access it in your char more easily. also save your playerController (which comes also out of createPlayer) as a reference in your sphere (when spawning with a variable exposed on spawn). you should always set the owner of a new actor to the actor which spawned that one, then you can access it in the child. I can upload you the changes I made if you like
I was thinking because of the style you program - everything in tick and with a lot of gates. learn about OOP, functions and events
I’ve uploaded it here:
say when you’ve downloaded. btw - if you share project, use file->zip project (or copy only content,config,plugins,source) - it is ~1GB of garbage
I’ve marked most of the things I changed with a blue comment.
I’m not came from Unity, I’m just a game designer
I’m not sure I’ve understood everything what you proposed, but if you can upload your changes - it would be great, I’ll try to figure out from the example
As I can see, what you’ve achieved with your changes, is that camera cam follow 2 spheres depending from which one I’m moving, right?
But behavior of both those spheres is totally broken. And, to be honest, I don’t see why for now.
Here how it works currently:
You can check how it was on the gif few posts above (now it stops to count distance on which I’ve stretched the sphere as a coefficient to the power and vector I apply on the sphere when I release it)
Second sphere behaves even worse - it’s just teleports to the first one when I’m clicking on it, and then first one starting to move like I would interact with it:
Also I’ve noticed, that you are spawning those spheres as an Actor BP (in player controller), but you recommended me to make them as a Pawn, right? So which approach is right?
sorry, I don’t have any idea what your game idea or mechanics is about. the changed thing - beside of using the correct player controller - is: uncheck the bool “accel change” in addForce again. the spawn event in your playercontroller is not connected - it still spawns the spheres in gamemmode. I put it there as an example how you could do it to pass the correct PC to the sphere on spawning easyli. you now have the connect playercontroller who spawned that sphere as a reference inside of your sphere for whatever you want to do with it. I’m still not sure what s the goal and if createPlayer is the right thing for you. it creates multiple local players - u usally use it for splitScreen (activate split screen in project settings to see what I’m talking about). I guess you want to create something turn based - which is something different