#Weird transform sets itself back to null

1 messages · Page 1 of 1 (latest)

unborn axle
#

Hi guys, i have an issue, i've been stuck on this for more than 5 hours now, and i can't seem to find an answer of why it is behaving this way.

I made a CameraManager. It attached to my main camera, and has 2 methods. One to set the camera to top down, and one to set the camera to ship (basicly a third person camera).

I will post a link to the actual code because i think it will be easier if you see it this way than trying to explain everything.

#

Basicly, when my player spawns a new ship, it calls the SetCameraToShip method

#

On the first ship spawn, it works perfectly

#

but the second ship spawn, the "target" of my controller is set with SetTarget, but right after that, in lateupdate, it is back to null

clever grove
#

send the code

unborn axle
#

Here 🙂

#

Sorry, took some time to remember what was the exact name of hatebin ><

#

@clever grove

clever grove
#

and the camera manager script?

#

also unrelated but please cache the camera manager script on Start method

#

also where are you getting the ship from

unborn axle
#

Wait, aparently i sent the wrong code?

clever grove
#

uhh idk

#

?

#

xD

unborn axle
#

Wait a sec, hatebin not saving my edits

#

Here it is

#

@clever grove

#

sorry for delay, hatebin doesnt want to work apparently

clever grove
#

ok, first off

if you only have 1 camera PLEASE cache the Camera.main

also you dont have to go Camera.main.gameobject you can just go Camera.main.getcomponent

#

legit half ur code is just Camera.main.gameobject instead of just camera

unborn axle
#

Yeah initially i cached it, but i was wondering if i was doing something wrong like not getting the actual camera

clever grove
#

if u only have one it should work

#

second, adding and destroying components all the time seems really inefficient. why not just have two scripts, one is topdown and one is ship and just enable or disable them based on the camera mode?

unborn axle
#

Yes it's true 🙂

#

What i dont get is why my SetTarget not working tho

#

on first ship spawn, it works

#

on second ship spawn, SetTarget works (The debug.log of SetTarget method outputs valid result, target is set correctly), but as soon as LateUpdate kicks in, i get a null ref for target

clever grove
#

o you didnt check for !isLocalPlayer

#

so it might be checking on other players

#

scripts

#

where target isnt initialized

#

dunno

clever grove
unborn axle
#

the camera controller and camera manager isnt NetworkBehaviour

clever grove
#

o right its on camera

#

nvm

unborn axle
#

Hihi

#

This drives me nuts ><

#

OnEnable : Target is null (set target not called yet)
SetTarget : Target is valid
LateUpdate : Target is null

#

Buut i think u might be right

#

I was doing my tests with one server and one client

#

i tried doing with just one host

#

and the first try it doesnt work

clever grove
#

idk exactly how your game is working in that way so its hard for me to know what thr problem can be

#

but im guessing multiple objects are calling to change the target

#

and you dont see it on logs

#

since sometimes its on client only logs

#

dunno

#

but you should see them

unborn axle
#

Welp, first ship spawn is this

#

second ship spawn is this