#💻┃code-beginner

1 messages · Page 51 of 1

swift crag
#

can't a component that's on the same object as the trigger still receive the message?

#

maybe i am mis-remembering

unreal phoenix
#

My favourite part of Unreal is the ability to add infinite colliders to even just one Object and just manually set up the subscriptions when the Object is made

polar acorn
#

GetComponentInParent also works if you call it on the object with the component on it

verbal dome
swift crag
#

yeah, give it a look real quick

#

i need to stop "giving things a look" in my actual projects

#

i keep finding random crap in my scripts

#

ah, int wtf = 123;, hello there

vale blade
#

git stash :)

swift crag
#

hmm true

#

git stash my work, do the thing, hard reset and reapply stash

#

I prefer to just have a few projects in different editor versions and render pipelines

#

but I cleaned all of those up recently

unreal phoenix
#

Can confirm what Osmal said is true

swift crag
#

Good to know.

#

well, also bad to know, because that makes things harder!

verbal dome
#

Also im just 99% sure thats how it is

swift crag
#

yeah, that should really be clearly documented

#

given how fundamental that is

unreal phoenix
#

The object with the collider will not recieve messages if the parent has a RB

verbal dome
unreal phoenix
#

weird

#

Unity colliders have always annoyed me

swift crag
#

i wouldn't think it would be hard to add that

#

Anything that moves away from messages, with their nitpicky names and occasional lack of specificity, would be a win in my book

vale blade
#

well I showed you how in that SO post :p

#

you just get a unityevent for what to do when the trigger occurs so you can link that up to any custom event system too

solemn fractal
#

is there a way to check in the method update, if something collided? I mean i want the experience on the floor to move toward the player. But for it to move, the move method needs to be inside the update. So what I need is like inside the update method something saying. IF the object collided, move.

#

becuase if I do that inside the on collision tigger the method is called 1 time and I need it to be called every frame to keep moving

slender nymph
#

Use a physics query like a Raycast or CheckBox

solemn fractal
#

hmm never used both.

buoyant knot
#

You should use Raycast/Cast/BoxCast/OverlapCollliders/etc if you want to know what is colliding in the middle of a normal evaluation.

#

You should use OnCollisionEnter/Exit/etc if you want a method to be called only when you enter/exit/stay in collision with something.

#

OnCollision methods let a script know what to do AFTER a collision happened. Casts let you move things while respecting collisions at any time.

solemn fractal
#

hmm ok ..got it

junior seal
#

How do I detect if a player enters an area? I put a box collider in the area that I want to be detected and it istrigger. Im having trouble code wise because im trying to access the colliders script from a gamemanager script and i dont think im doing it correctly.

verbal dome
#

Put a OnTriggerEnter on the area/box collider object

junior seal
#

Because the gamemanager has a whole lot more information

verbal dome
#

The method has a parameter for what collider entered it

junior seal
#

My Game Manager

{
    public static GameManager instance;
    public GameObject player; //test

    int enemiesRemaining;

    //door stuff - Dami
    EndDoor endDoor;
    [SerializeField] GameObject door;
    FinishLine finish;
    [SerializeField] Collider box;
    static private int floorLevelMax = 1;
    int currFloorFinish;

    public bool isPaused;

    void Awake()
    {
        instance = this;
        endDoor = door.GetComponent<EndDoor>();
        finish = box.GetComponent<FinishLine>();
        player = GameObject.FindWithTag("Player");
    }

    public void UpdateGameGoal(int amount)
    {
        enemiesRemaining += amount;

        if(enemiesRemaining <= 0)
        {
            StartCoroutine(endDoor.OpenDoors());
            ExitDoorCondition();
        }
    }

    public void ExitDoorCondition()
    {
        if(finish.isInBox == true)
        {
            currFloorFinish++;
            Debug.Log(currFloorFinish);
            if(currFloorFinish == floorLevelMax)
            {
                YouWin();
            }
        }
    }

    public void statePause()
    {
        isPaused = !isPaused;
        Time.timeScale = 0;
        Cursor.visible = true;
        Cursor.lockState = CursorLockMode.Confined;
    }

    public void YouWin()
    {
        Debug.Log("We got here at least");
        statePause();
        currFloorFinish = 0;
    }
}```
solemn fractal
#

Hey guys I have a prob here, cant understand why.. it was working and now its not.. and I am confused. I have this message. but in the code I have like this

junior seal
#

My Collider```public class FinishLine : MonoBehaviour
{
public bool isInBox;

void OnTriggerStay(Collider other)
{
    if (other.CompareTag("Player"))
    {
        isInBox = true;
    }
}
void OnTriggerExit(Collider other)
{
    if (other.CompareTag("Player"))
    {
        isInBox = false;
    }
}

}```

short hazel
solemn fractal
#

already have it

short hazel
#

Then you have another script attached somewhere else, that doesn't have it

#

Like below the Circle collider here

solemn fractal
#

oh no

#

i didnt see it.. might have dragged

#

byt mistake.. damn I am so tired like 10h straigh in unity + work

#

I think i am going insane

#

need a rest hahah thank you !

summer stump
junior seal
#

what do you mean?

summer stump
junior seal
#

the boolean

summer stump
#

What is the goal of this? To call YouWin?

short hazel
#

"Tell me you copy-pasted the code without telling me you copy-pasted the code"

summer stump
short hazel
#

GameManager has a singleton setup. It has a static field you can access anywhere that will refer to the one GameManager in the scene, use it

junior seal
#

the boolean in finish line. I need to check if it is true, bc if it is, i need the things in ExitDoorCondition to happen

summer stump
#

Don't check the boolean

junior seal
junior seal
summer stump
junior seal
#

Sorry im not totally familiar with this. I literally just learned what this was like 4 days ago

summer stump
#

GameManager.instance.ExitDoorCondition();

junior seal
#

okay cool. thanks

queen adder
#

Is there a way to tell Unity when to compile ur code rather then on each time u save a file

swift crag
#

You can set the editor to not automatically reload

#

preferences -> asset pipeline -> auto refresh

#

It will recompile when you hit ctrl-R, or when you create/move/delete a script asset

#

I guess that, more pedantically, this just means it doesn't look for changes to files until you hit ctrl-R

#

if you create a new script asset in unity, it sees the change immediately

short hazel
#

And then there's CompilationPipeline.RequestScriptCompilation() method if you want to trigger a compilation via code, like with an editor window or context menu

queen adder
#

Oh both methods are pretty cool!

#

Thank u this is gonna be a huge time saver

solemn fractal
#

hey guys.. why that doesnt work? the game object with this script always go towards the player.. even if I dont move with the player .. this object goes inside the player to its center, but even tho they have same position .. the object is not deleted

summer stump
wintry quarry
queen adder
#

Yeah lol^^

wintry quarry
#

Also why are you checking the same condition twice?

solemn fractal
#

so if its unlikely how do I do that check? is there a way to say, if u are 1cm from the player delete?

queen adder
#

I just dont like having to compile alot because compile times in Unity are pretty slow compared to Godot or unreal IMO

wintry quarry
#

check within a certain threshold, yes

solemn fractal
wintry quarry
#

Vector3.Distance(a, b) will give you the distance

#

then you can check that it's within some small amount

summer stump
solemn fractal
#

ah.. he said vector3.distance

#

so i thought that was a vector3

summer stump
#

No, the type on the left

#

Did you look at the error?

#

Or the docs for Distance?

solemn fractal
#

yeah

#

so need to set as a float

#

ok

#

thank you

wintry quarry
#

it's just a number

short hazel
#

"I cannot put a float into a variable of type Vector3" would be a more user-friendly message

swift crag
#

When you try to use a variable of type Foo in a place that wants a Bar, C# will try to convert it.

#

Since you did not explicitly ask for a conversion, this is an implicit conversion

wintry quarry
swift crag
#

If this is impossible, you get an error.

#

You will get a different kind of error if you try to perform a cast (an explicit conversion) between two incompatible types.

#

Sometimes an explicit conversion is legal, but an implicit one is not

solemn fractal
#

now its working.. thank you

swift crag
#

e.g. float explicitly, but not implicitly, casts to int

solemn fractal
#

now i need to learn about this checkbox or raycast to use instead of ontrigger enter.

short hazel
swift crag
#

indeed

#

the thing i find funny is how int to float is implicit

#

even though, by definition, the number of floats that loses precision when they become an int is exactly equal to the number of ints that lose precision when they become a float

buoyant knot
#

doesn’t implicit just mean you don’t have to ask?

summer stump
#

No cast required

buoyant knot
#

that’s what I thought. making sure

topaz mortar
#

For everyone in here who has helped me, I just posted a first (very early) preview of my game in #archived-works-in-progress
Just wanted to let everyone here know, so you can see what you have helped me build so far 🙂

hoary halo
#

Hi. I have been stuck on this problem for a bit now. Im trying to reference this playerInventory script in my script but it wont let me do it in any way.
public Inventory playerInventory; Player.cs

using UnityEngine;

public class Inventory
{
    public List<Weapon> ownedWeapons = new List<Weapon>();

    public void AddWeapon(Weapon weapon)
    {
        ownedWeapons.Add(weapon);
    }
}
``` *Inventory.cs*

Everything else will show but not inventory. Not even while debug mode turned on
eternal needle
polar acorn
sand veldt
#

Hello i am using AI in unity

agent.stoppingDistance = range;

void Chase()
{
// if (Vector3.Distance(transform.position, player.position) > range)
{
Movements(player.position);
}
}

is if here is usefull or not i am calling Chase function in Update

summer stump
sand veldt
eternal falconBOT
summer stump
#

Can't say if it's useful. You tell us if that's what you want

sand veldt
#

i want the enemy to chase player

#

and stop at a certain distan

summer stump
sand veldt
#

i am using this also
agent.stoppingDistance = range;
is if statment needed or not

languid spire
sand veldt
sage mirage
#

Hey, guys! I have a question. I want to make in my game a functionality that when I click QuitButton to exit playmode and application, I want it to happen with a delay of 1 or 2 seconds. I was thinking to use IEnumerator in order to achieve that and also was thinking to use waitforseconds to do that. Can you please tell me which way is the best to make this functionality work?

summer stump
tiny hawk
#

Question: I'm using the free FIrst Person Character Controller, and I'm getting the following error when trying to declare a variable using a class from one of it's scripts:

I tried that and I get the following error:

Assets\Dudesss Custom\Furniture\Scripts\FreeObjectPlacement.cs(16,16): error CS0246: The type or namespace name 'FirstPersonController' could not be found (are you missing a using directive or an assembly reference?)
languid spire
tiny hawk
polar acorn
summer stump
dry tendon
#

!code

eternal falconBOT
languid spire
languid spire
polar acorn
# tiny hawk

Are you using that namespace in the script that's trying to reference this class?

tiny hawk
#

I figured with using, I could call the other namespace's class

sand veldt
timid gale
summer stump
eternal falconBOT
novel thorn
#

Hello guys

dry tendon
#

heey, hello everyone again... I need help with location permissions on my game in android... This is the code https://gdl.space/xayokuhipu.cs the game ask for location permissions on awake, that works correctly, but the first time the game ask you for location permissions it doesn't send your coordinates to the API, that doesn't happen again when you restart the game... Could someone help me? I have no idea about what's happenning...

loud storm
#

why is my project taking so long to load???

languid spire
dry tendon
timid gale
polar acorn
languid spire
polar acorn
#

Although if you have assembly definitions in your project, you also need to make sure the assembly has a reference to that namespace's assembly

loud storm
#

im hella new

tiny hawk
summer stump
modest dust
modest dust
timid gale
loud storm
#

so why it loading so slow

languid spire
loud storm
#

it has been loading for 12 mins

summer stump
dry tendon
polar acorn
tiny hawk
novel thorn
polar acorn
green copper
#

what's the syntax to make an instantiated prefab have the position and rotation of the parent object?

summer stump
polar acorn
green copper
#

ohhh I see, I did have it right, it just didn't register the syntax for the first argument as correct until I typed both

#

it told me it couldn't convert from Vector3 to transform

#

what does this mean?

#

google is being inconclusive, something about the editor being open too long? a few people saying "nvm fixed" and not saying how

polar acorn
#

It's not anything related to your code, I'd say just restart the editor and see if it goes away

green copper
#

it seems to have

#

but,
worrying

solemn fractal
#

hey guys, how do I check on update for something that enter my collider if I cant use the ontrigger enter method as it call things 1 time. checked raycast and box something but cant understand how to do it. any help?

solemn fractal
#

oh

#

really ?

#

but actually.. what I want is more specific

eternal needle
#

then describe it more specifically, what are you trying to do if not be notified constantly about something inside the trigger

solemn fractal
#

So basically what I need is that I have a player.. when I kill a monster he drops exp on the floor.. and I want that when I get near the exp .. it will fly to me. But my player has a collider to check other stuff so I am using another empty object that follow player position with a trigger to check that collision with the exp

#

but the prob is that the script is on the object that will collide the empty one.. and I need to call the method MOVE on the exp script

#

but it needs to move only after entering the area of the trigger of the empty object

#

and that is it

#

this is the movement and it is working

#

now I just need to make that move be called when I enter

lusty socket
#

!code

eternal falconBOT
solemn fractal
#

the area that I can collect

eternal needle
lusty socket
solemn fractal
tiny hawk
lusty socket
#

hi just wondering if anyone could help with my invoke? just wanting to delay the asked for request bt 2 seconds but in game it just says invoke couldnnt be called, thankyou

frosty hound
eternal needle
# solemn fractal

this isnt an empty object if there is a collider on the object, but regardless OnTriggerEnter you just check if the object has the script you are looking for. If it exists, then call Move and pass the transform in as a parameter

frosty hound
#

And you cannot use parameters

lusty socket
frosty hound
#

Because your function has parameters. In other words, you cannot use invoke for what you're doing.

lusty socket
frosty hound
#

A manual timer in update, or a coroutine.

lusty socket
frosty hound
#

Coroutine will work.

#

Manual time is tracking deltaTime in update by storing it into a float variable and checking if it has surpassed some value.

lusty socket
frosty hound
#

Your IDE should be throwing an error

lusty socket
#

This is the error i recieve using a coroutine in my code as shown above

frosty hound
#

Yes, because you're not passing anything to the coroutine and it's expecting it.

lusty socket
#

what should i pass through? this is how it was shown in the video just obviously with my additions in

frosty hound
#

Whatever you want message to be? Think for a second of what your function is actually doing.

lusty socket
#

showing a desription of the item

polar acorn
#

What value do you want message to be

lusty socket
#

is the value not the 2 for 2 seconds

polar acorn
frosty hound
#

Your functions purpose (assuming you actually know its purpose), is to display a message on a text component as a tooltip.

When you call that function, you have to give it the message to display as outlined by the functions parameters that you've made.

#

But I'm starting to realize this is likely a copy paste attempt at functionality with little to no knowledge of coding.

lusty socket
#

i watch videos to try learn what to do and add and use them to complete the actions i need, in this instance id have only known how to use a invoke but am in unknown territory here, the actual terminology behind alot of the code keywords kind of go over my head causing me to misunderstand alot which i apologise for, i usually just learn better being taught it first then figure out how to apply it into my own, as this is a little slip up i just need a little help with ive turned here for some help

frosty hound
#

This isn't about invoke or coroutines or how to make something happen after an amount of time, it's basic coding and understanding of functions.

#

You may want to do a tutorial on basic coding

polar acorn
quiet gazelle
#

hello. i have a rigged model GO (with no components, freshly instantiated), and an animation clip array. what is the simplest way to make that model play the animations in the array at runtime?

lusty socket
polar acorn
lusty socket
#

parameters are the bools float etc i thought, am i wronh?

frosty hound
#

Wrong

polar acorn
frosty hound
#

SetAndShowToolTip(string message)

It's expecting you pass a string representing the message when you call the function.

lusty socket
lusty socket
#

so do i need to add my message i want to be displayed on screen in the brackets ?

#

for this to work

#

or am i way off

polar acorn
lusty socket
#

i have the message set up in a different script thats added to the items to give them each specifc item descriptions

polar acorn
lusty socket
#

but isnt my value different with each different item description?

lusty socket
#

in the brackets

polar acorn
#

What value do you want to pass to that function

lusty socket
#

the item desription

polar acorn
lusty socket
#

but thats different with every item because its in another script

#

so the value can differ depending on the item

polar acorn
#

So what item description do you want to show

lusty socket
#

one for each food i pick up

#

so 3 different item desriptions

#

not just 1 specific item desription

#

one with like the ingredients for pie when hovering over pie

polar acorn
lusty socket
#

one for cake ingredients

lusty socket
#

so i have the script youve seen

polar acorn
unkempt stag
#

I have a Vec3 that is the normal of a plane. I have two other Vec3s, A and B. How do I get the angle between A and B on that plane normal?

lusty socket
#

then

polar acorn
#

Yes this is the code I am looking at

lusty socket
#

it goes into the next sccript the setandshowtool

polar acorn
#

This is the same code that I have been looking at. What value do you want to display when this object is created

lusty socket
#

then when attaching this script to the desired item i can enter whatever message i wish in the inspector

polar acorn
quaint jolt
#

I am getting an error can someone help me

polar acorn
#

But also irrelevant

quaint jolt
#
Invalid file content for Library/StateCache/SceneView/8c/8cd7c613bf844de3b80696e27a479d5e.json. Removing file. Error: System.ArgumentException: JSON parse error: The document is empty.
  at (wrapper managed-to-native) UnityEngine.JsonUtility.FromJsonInternal(string,object,System.Type)
  at UnityEngine.JsonUtility.FromJson (System.String json, System.Type type) [0x0005c] in <4648fab9f0e14a8c97a9b3401f73e835>:0 
  at UnityEngine.JsonUtility.FromJson[T] (System.String json) [0x00001] in <4648fab9f0e14a8c97a9b3401f73e835>:0 
  at UnityEditor.StateCache`1[T].GetState (UnityEngine.Hash128 key, T defaultValue) [0x00067] in <273a7cbcc8d7454ea7ae78e07082aa77>:0 
UnityEditor.WindowLayout:LoadDefaultWindowPreferences ()
polar acorn
quaint jolt
#

i did

lusty socket
quaint jolt
#

it still wont let me test it untill it is gone

polar acorn
# quaint jolt i did

Close your project, delete the Library folder, then re-open the project and let it regenerate the Library

polar acorn
#

That's the one you need to fix

austere monolith
#

Hello, I've been having some trouble lately and I came here to understand why. I make the player movement script, and the mouse looking script... I place a game object and I try pressing against it. I see that I can walk through it and just put a box collider on it. I try again but i can still walk through it? I went on ChatGPT before this and i did all the things it told me but it never worked... Does anyone know what I could do?

quaint jolt
#

oh, nvm thank you @polar acorn

lusty socket
polar acorn
austere monolith
# polar acorn How are you moving the player

void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");

Vector3 movement = new Vector3(horizontalInput, 0.0f, verticalInput)

transform.Translate(movement * moveSpeed * Time.deltaTime)

}

and i already put the movespeed variable

polar acorn
eternal falconBOT
polar acorn
#

If you want physics, you have to use physics. Either a Rigidbody or a CharacterController

austere monolith
#

Thank you so much!

polar acorn
lusty socket
#

the item description

polar acorn
lusty socket
#

3 different items

nova bluff
#

hello, just get started with unity, should i start lookin into linear algebra of some geometry in order to learn how to manipulate 3d object?

also could someone, please, share some websites with free 3d assets?

polar acorn
lusty socket
#

i dont just want 1 to work i want alk 3 of them to work

polar acorn
lusty socket
#

no each individually when hovered over my mouse cursor

polar acorn
#

I'm asking about what value do you want to display in Start of TooltipManager

lusty socket
#

when the game starts nithing

#

until an item is hovered over

polar acorn
#

What value are you trying to display here

polar acorn
#

If you don't want to display a message in Start

lusty socket
#

nothing until an item is hovered over

polar acorn
open apex
#

what is "null"

polar acorn
lusty socket
#

where does it need to be set up then to only appear when an item is hovered over

polar acorn
lusty socket
#

but i want a 2 second delay before the item desription is shown

polar acorn
lusty socket
#

but your saying it needs to display a message when started

open apex
lusty socket
#

i dont want that

polar acorn
#

and I'm asking why

lusty socket
#

i want it when the specific item is hovered over

polar acorn
#

when it seems like you don't want that

lusty socket
#

to do what i am asking

polar acorn
austere monolith
#

Digiholic are you someone who is advanced helping the beginners?

lusty socket
#

but how do i say that in code

#

like i cant type the code when hovering over an item to say do it now

polar acorn
#

So why are you trying to display something in Start as well

lusty socket
#

but how do i add a delay to that

austere monolith
#

!code

eternal falconBOT
polar acorn
lusty socket
#

thats what im askinf

#

where does the coruitine need to go though if not in start thsts what ive asked

polar acorn
#

Which in this case is on hover

lusty socket
#

when an item is hovered over

polar acorn
#

So, there

#

Start it there

lusty socket
#

so i need to do it in the other script for onmouseenter

polar acorn
#

Yes, start the coroutine there

lusty socket
#

fixed it thankyou

open apex
#

Hello, my brain is about to crash, I need some explaining from someone please.
I am watching this tutorial video where we create a script called "PlayerMovement"
and we also create a script called "PlayerCollision"
https://prnt.sc/0KhhmW7aj37L There is s "PlayerCollision" variable we wrote called "movement", in order to refer to the "PlayerMovement" script we wrote line 7.
But why do we have to we have to put "PlayerMovement in the empty slot in order for it to work, haven't we refered it in the script yet?
https://prnt.sc/0dAPF_PeZmdD
https://prnt.sc/pqPkBX04AP_r

Lightshot

Captured with Lightshot

Lightshot

Captured with Lightshot

Lightshot

Captured with Lightshot

#

please someone explain

polar acorn
open apex
#

wow

#

so what did I write "public" for

polar acorn
#

So you can set it in the inspector?

#

and reference it in other scripts?

#

Theoretically, it looks like you could just as easily have done [SerializeField] private instead

north kiln
eternal falconBOT
open apex
#

so you cannot refer it from the script?

polar acorn
#

I don't think anything else is gonna reference this

polar acorn
open apex
#

It took me 1 hour

polar acorn
north kiln
open apex
#

there was no IDE at all

polar acorn
open apex
#

now there is a kinda working weird IDE

#

I don't want to break it

sour fulcrum
#

There still isn't

polar acorn
eternal falconBOT
open apex
#

which one should I use

polar acorn
north kiln
#

??? Just configure the one you're using

open apex
#

installed via unity hub?

north kiln
#

Did you install it via the hub?

open apex
polar acorn
open apex
#

because IDE didn't work

#

I will just do both methods

#

😎

#

I'm too cool

north kiln
#

As long as you have one IDE that is properly configured, with it being what is opened and configured in the External Tools settings then it should work

sour fulcrum
#

No one is asking you to do both, your being asked so they can help you with the context needed

open apex
#

this is the best I got

sour fulcrum
#

I'm aware, and software sucks

#

But the thing people suggest you get an IDE for isn't working for you currently

open apex
#

😎

open apex
#

🤙

#

external tools keep getting switched I don't know why

open apex
tiny hawk
#

@polar acorn I'm sorry, but I still didn't figure out how to reference the FirstPersonController script. I don't know where it's Assembly definition is.

polar acorn
#

!code

eternal falconBOT
crystal cipher
#

this should say in units like "K" and "B"

#

for example. instead of 7,025 it shows in 7K

#

but when I debug Log it, it does work properly

#

but not the textbox

polar acorn
#

If your log displays that value then your text is being set to that. Are you sure the text you're looking at is the one this script is referencing and that it's not being set somewhere else

crystal cipher
#

umm.. no

#

playerprefs coins exsists

#

also

polar acorn
#

Why are you using find, and why are your variables of type game object. Just make a public variable for the text component and drag in the object you want directly

crystal cipher
#

oh

grim ether
#

yo i have a collider in this 3 d game and it get turned on during animation and i have a code saying if acollison happens on this other object it get deleted but when i play the animation to swing the hammer down the object thats supposed to be deleted because of the contact does not get deleted what do i do?

polar acorn
#

Show code

grim ether
#

how do ido it again on this sever have been onthis server since forver

#

here very simple

summer stump
grim ether
#

ok

polar acorn
grim ether
grim ether
polar acorn
grim ether
#

ok

#

object trying to destroy

#

hammer

polar acorn
#

Which one has the rigidbody

grim ether
#

none

polar acorn
#

So fix that

grim ether
#

well i had one but it didnt do anything

#

now some how its workin even tho before i had one and it didnt work

#

well now i have a massive glith

#

glitvh

#

glitch the hammer pice get disconected and starts flying like super man bro

grim ether
unique violet
#

Is there a unity function that gets called when an object gets SetActive(true); ?

#

is it OnEnable() ?

static cedar
#

Ye.

unique violet
#

ok

#

thanks

queen adder
#

Which GetMouseButton is it for XButton4?

#

i tried with index 4 but it doesnt work

#

maybe 6?

#

if 0 and 1 are Left click and right

unique violet
#

why doesnt this work?

print(gameObject.transform.transform.parent.parent.name);
        textAssetText = gameObject.transform.transform.parent.parent.GetComponent<SettingsPopup>().textObject;
        imageComponent.color = textAssetText.color;
        colorField.text = ColorToHex(imageComponent.color);
gaunt ice
#

What is image component

eternal needle
unique violet
#

no i have it

ivory bobcat
#

Or text asset text (text object) was null

unique violet
#

thats just so confusing then because its not null

ivory bobcat
gaunt ice
#

The text object should not be null, log them both

eternal needle
#

🪄 debug them both so you dont have to guess by looking at the inspector

gaunt ice
#

You can just log them to see if they are null

ivory bobcat
unique violet
#

alright

hardy fjord
#

trying to add a check so it doesn't destroy the enemy gameobject before detecting another collision from the projectile game object since with raycasting i ran into the issue where the enemy would destroy before the fake projectile would reach it

#

have not been able to figure it out

unique violet
#

How can I cache a current object and all of its children then when I want to revert everything back to that state?

hardy fjord
#

the note at the top of enemy cs can be ignored i forgot to remove that

gaunt ice
#

If you want to “revert” some objects back to some state, you need undo function, not just caching

unique violet
#

if there isnt a simple way to do it thats fine

#

ill just work my code for it

gaunt ice
#

I remember unity provides some undo function you may search it

eternal needle
# unique violet well the problem is im changing a lot continuously

could just use version control for this if its a lot of changes. Create some branch, work on that branch, if it doesnt work then just go back to the main branch without merging. If you want to keep some small changes along the way, then commit those and undo the others

#

otherwise you would be looking at making a custom editor script to store everything, which could work but its more effort for something that may be buggy

queen adder
#

hello

#

how do I create a simple first person controller?

#

I've looked at heaps, but they're whack

teal viper
#

Define "whack"

green copper
#

how can I make a prefab have a constructor with an optional argument? i want to have the option of inputting a size for an object, but if no argument is given, have a default value

#

and will it work with Instantiate()?

eternal needle
#

or adjust it after instantiate, depends what object you are adjusting

green copper
#

Making an asteroids clone for a project, was planning on

asteroidBreakFunction
{
makeTwoClones(0.5 current size)
destroy(self)
}

#

or alternately

asteroidBreakFunction
{
makeClone(0.5 * current_size)
makeClone(0.5 * current_size)
destroy(self)
}

#

pseudocode, I know the syntax is wrong

#

just planning

eternal needle
green copper
#

Ohhhhh right, I forgot that instantiate leaves a variable to play with behind

eternal falconBOT
versed light
#

whats the difference between transform.SetParent(parent) and transform.parent=parent

#

they one and the same or is one more stable etc?

summer stump
#

Oh, yep
"This method is the same as the parent property"

versed light
#

ah okay thanks

green copper
#

the objects made by this function are disabled, along with all the components

#

I double checked and even remade the prefab, it's not prefabbing a disabled object

young warren
# green copper

Just to be sure, show the inspector of the asteriodPrefab object?

green copper
young warren
#

And the clones are disabled? Not just invisible?

green copper
#

the object, the collider, and the breaker script

young warren
#

Fracture doesn't have any code that disables this?

#

Or any code anywhere that disables this asteroid?

green copper
#

Fracture was leftover code, removed with no consequence

#

and I'm just starting on any asteroid handling code of any kind, nothing should touch it

young warren
#

Can you test by making a brand new prefab which is just a plain cube, no scripts, no tag, and set that as asteriodPrefab for now?

#

Unless asteroidPrefab is not GameObject

green copper
#

like this?

#

the cubes still exist

young warren
#

Does the asteroid have a tag?

green copper
#

yes, it has the tag 'asteroid'

#

it needs that for the laser collision detection code

young warren
#

If you untag it, use your original prefab, see what happens

#

I'm just trying to figure out possibilities here. Thanks for your patience and cooperation so far

green copper
#

and thank you for yours

#

okay

#

strange thing

#

did the first part

#

I mean, second

#

okay let me start over

#

I replaced the prefab with asteroid1 again

#

now the first set of children are enabled

#

the second generation are not

young warren
#

Are you using object pooling

green copper
#

this is sort of a recursive system, every time the asteroid is destroyed it's going to be replaced with two 50% scale clones until it hits a minimum

green copper
young warren
#

Show code where asteroid is destroyed?

#

And the replacing with clones part

green copper
#

this is attached to the projectile

#

this is attached to the asteroid

young warren
#

Okay, I'm going to suggest you ctrl+shift+f and search for SetActive

#

See if there's any that passes in false

green copper
#

new error message btw

#

no instances of SetActive with a false pass anywhere in files

young warren
#

Then it might be because of that error message, I'm not sure

#

Try to refactor your code to not spawn inside the OnDestroy

#

Sorry I'm out of ideas

green copper
#

thanks for trying

queen adder
#

Try to use ondisable

frosty flicker
#

making a five nights a freddys fan game and i want to sork on the like office movement I know i need to use clamp to do the classic movement style but would cinemachine be the best way of making it so the further to left or right i go the faster it moves

pastel vector
#

If I subscribe to an event when a scene loads and both the object that causes the event and the subscriber will both live the entire scene do I still need to unsubscribe? The reason for not wanting to do so is that I will need to add a reference to the event caller on the subscriber and that seems like unnecessary coupling

cosmic dagger
solemn fractal
#

hey guys, if I have this setup here, where I have a prefab experience with an array of gameobjects, and I referenced inside that array 3 dif exp tpes. and inside the enemy when it dies I am saying drop(instantiate) the experience. But is there a way to tell which one?

pastel vector
cosmic dagger
solemn fractal
#

it wont allow me

cosmic dagger
solemn fractal
#

hmm.. so i need to create a method in ExperienceLevels, that is called when the enemy die in the enemy script

cosmic dagger
solemn fractal
#

and that will tell which one to spawn?

pastel vector
#

There is no way of unsubscribing without adding a refference to that object right?

cosmic dagger
solemn fractal
#

it is just very hard for me yet to think and choose which scripts to create and where to put things..

#

Its harded than coding it self. Sometimes I get lost for hours just trying to ifigure out where things will be

#

if I create a script only for exp.. or if I create 1 for the enemy and inside the enemy it will contain the experience logic etc

#

so hard to decide those things

#

also if I have 5 types of enemy.. dont know if I create 1 script and control all or should i create one for each.. or create 1 prefab for all and control it with other prefab

#

and things like that so hard to decide and understand

cosmic dagger
#

hmmm, you could unsub in the subscribed method, but only if the event is invoked before the GameObject is destroyed . . .

eternal needle
cosmic dagger
solemn fractal
cosmic dagger
cosmic dagger
# solemn fractal hmm.. and as a good practice or best way to do it. always when I have like 10 en...

if each enemy type has a group of experience they can provide, i'd use a ScriptableObject holding an array of the experience prefabs. if all enemies pool from the same group of experience prefabs, then using the SO works just fine. every enemy will point to the same SO in memory and randomly select from that pool

if a group or specific enemy uses a single experience prefab, place a check in the enemy script to avoid selecting from the array . . .

eternal needle
# solemn fractal also if I have 5 types of enemy.. dont know if I create 1 script and control all...

Each enemy will have similar behaviour right? Ex: regardless of who the enemy is, they may have an idle, moving, attacking mode.
Calling the functionality for these 3 examples should be done from 1 script, while the idle, walk, or attack functionality can differ between them. Like one may idle by standing around, one may wander, this functionality can be in another class and plugged into your enemy class

solemn fractal
#

will check you guys input in some minutes, thank you for ur feedback, just finishing some work stuff.

minor viper
#

Im trying to make a cube runner game for mobile but how do i make a working script so it works

#

looks like this now

#

i want it to jump when you click

#

i did check a tutorial but it dosent work

cosmic dagger
topaz mortar
minor viper
#

lemme try it again

merry spade
#

how can i call a function as a prefab?

#

if the ore is being mined the "hp" of the ore should go down and if they hit zero the prefab calls a function that adds money

#

but i cant get a reference to the moneyscript

gaunt ice
#

are you trying make object in scene reference some script on the prefab?

minor viper
#

I made Exactly like the tutorial can anyone help me

keen dew
#

That's obviously not even close to what the tutorial shows

minor viper
#

i did like he did

keen dew
#

No you didn't

#

Link to the tutorial please

minor viper
languid spire
#

that is definitely one for @polar acorn

minor viper
#

He did like that but im trying and it dosent WORK

gaunt ice
#

so do you compare his code to your code?

keen dew
#

How do you suppose those are the same as what you have

minor viper
#

IDK IM NEW TO PROGRAMING

keen dew
#

New to reading too?

merry spade
#

i dont know how to get a reference

minor viper
#

no its just like everything he does when i try it dosent work

merry spade
#

the prefab should call a script function that is on the player

keen dew
#

Do it the same way and it'll work

minor viper
#

i cant cuz everytime i do it dosent work

#

bro try it yourself it to write the code exactly like that it wont work

keen dew
#

Why don't you try it yourself first

#

because the code you showed was just nonsense

#

do it the same way as the tutorial and then come back

minor viper
#

I REMADE IT LIKE 5 TIMES THE THINGS HE USEDOSENT POP UP OR IS ON MY KEYBOARD

gaunt ice
keen dew
minor viper
#

I AM TRYING AND IM DOING MY BEST

keen dew
#

if you don't know how to type a character then either google it or ask

minor viper
#

I DID GOOGLE IT AND ITDOSENT WORK

keen dew
#

Ok cool. If you can't follow a tutorial then there isn't much we can do for you

gaunt ice
#

first check the syntax, you have mismatched '{'

#

and syntax of function call rb.addforce is wrong

minor viper
#

imma just use chatgpt

#

Its supposed to come jumpforce here but it dosent work

modest dust
#

Using chatgpt might be even worse

#

What's your error

minor viper
#

this is my script

#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
private Rigidbody rb;
public float jumpForce;
private bool canJump;

// Awake is used for initialization
private void Awake()
{
    rb = GetComponent<Rigidbody>();
}

// Start is called before the first frame update
void Start()
{
    canJump = true;
}

// Update is called once per frame
void Update()
{
    if (Input.GetMouseButtonDown(0) && canJump)
    {
        Jump();
    }
}

// Handle the jump logic
void Jump()
{
    rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
    canJump = false;
}

// Handle collision events
private void OnCollisionEnter(Collision collision)
{
    if (collision.gameObject.CompareTag("Ground"))
    {
        canJump = true;
    }
}

}

#

jumpforce dosent comme up

modest dust
#

```cs
code
```
Post the code correctly

merry spade
minor viper
modest dust
#

As written above

minor viper
#

like where in the above

modest dust
#

start with ```cs on the first line

#

paste your code

#

end it with ```

gaunt ice
#

warp your code in ```cs your code here```

minor viper
#

Can you show screenshot?

merry spade
#

wait i'll do it for you

#
public class PlayerController : MonoBehaviour
{
    private Rigidbody rb;
    public float jumpForce;
    private bool canJump;

    // Awake is used for initialization
    private void Awake()
    {
        rb = GetComponent<Rigidbody>();
    }

    // Start is called before the first frame update
    void Start()
    {
        canJump = true;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0) && canJump)
        {
            Jump();
        }
    }

    // Handle the jump logic
    void Jump()
    {
        rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
        canJump = false;
    }

    // Handle collision events
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("Ground"))
        {
            canJump = true;
        }
    }
}
minor viper
#

thanks

modest dust
modest dust
gaunt ice
#
gameobject go=instantiate(prefab);//or instantiate the script directly
go.getcomponent<script on ore>().init(pass the reference to moneyscript to script on ore)
```some ways like this
minor viper
#

copied his code that dosent work

modest dust
#

Sure, but what doesn't work

minor viper
#

On this playercontroller script its supposed to come jumpforce that dosent work

modest dust
#

Are all errors resolved throughout all your scripts?

minor viper
#

think so

gaunt ice
#

do you save the script or there are any compile errors

modest dust
#

If there are any errors present then the code will obviously not compile

#

And the new version won't show up

#

New version being these fields that were meant to show up in your player controller script

minor viper
#

mabye works now

modest dust
#

First resolve any errors you might have, recompile and then check

minor viper
#

IT WORKS

modest dust
#

Good

minor viper
#

FINALLY

modest dust
minor viper
#

new to unity and programming

modest dust
#

Then I recommend learning C# first

#

Or else you're gonna have a bad time

minor viper
#

ye but thanks fo the help

modest dust
#

Good luck either way

#

Just don't try forcing yourself into Unity without learning the basics (C#) first

merry spade
#

ah i have to create it first right?

gaunt ice
#

ofc not defined, you have to create this function on your script first (and the field of type moneyscript)

merry spade
#

yes ok

gaunt ice
#

then the ore get the reference to the script on player

azure zenith
#

How can I disable a game object?

gaunt ice
#

setactive

azure zenith
#

On the UI though

#

Is it the eye icon?

modest dust
#

You click the gameobject

#

and deselect the tick in the upper left corner of the inspector

#

also not a code related issue in that case

azure zenith
#

Marvellous, thanks

#

My bad

merry spade
#

i did it thank you @gaunt ice

spark trail
#

Hi guys, I have a problem. I'm using the latest unity 2022.3.11f1 and I have just started using Unity having not used it for some years and wanting to get back in it. I have noticed that whenever I create a Enum list , save it, let it do its magic in Unity, then look at the script with the Enum in there, the IDE will freeze and lag for about 10-20seconds before eventually becoming normal again. I don't know what is causing this and the enum is not exactly hugh... it can just be 1 item in the list and it will lag just from switching away from the script to another script and then back, and it freezes again. Any ideas on how to get this to stop doing this?

#

this is all the code that is in there at the moment, and this is causing IDE to freeze?

teal viper
#

Though, usually it wouldn't affect the vs itself. I think...

toxic cloak
#

Why is my character starts to floats when i add a RB and m only using the rb for gravity and the gravity is set to -40 globally

teal viper
toxic cloak
#

boxcollider

#

animator

brisk escarp
#

Just a heads up I'm going to be posting a decent size help question

teal viper
toxic cloak
#

yeah a min

brisk escarp
# brisk escarp > Just a heads up I'm going to be posting a decent size help question

(i may be in the wrong room so let me know if i am.)
i am writing a enemy controller script and for some reason when the enemy touches the player #1 The player wont take damage, i know the damage and hp work as i have tested the hp earlier. #2 when the enemy touches the player it just rebounds and goes in a different direction randomly and i dont know why that is.
i can provide the scripts if you want to look at them.

teal viper
brisk escarp
#

alright give me one moment

azure zenith
#

member names cannot be the same as their enclosing type - What does this mean?

teal viper
#

The real question is why is it floating before the play mode.😅

toxic cloak
#

lol my bad it was the animation that came with the model that was messing my bad i figured it jeez

spark trail
# teal viper It's probably unity recompiling the assembly after code changes. You can disable...

I'm aware of the compiling after a change, that's fine, but unfortunately thisis beyond that. The other scripts that do not include Enums will save, and compile. (The bit I refered to earlier by magic Unity stuf) however, without any changes. If I then switch to another script from the tabs, then switch back to Enum without doing anything to either scripts, the editor freezes for about 10-20seconds. It's like having 1 FPS. You can see the cursor moving in the places you're clicking on within the script but its heavily delayed and takes about 10-20 seconds to fix itself. Unity itelf is doing nothing its just the IDE that seems to be doing something. ONLY when an ENum has been put into the code. If I delete the enum, I can switch all day everyday and it's instant, I can click on the script anywhere and type, and it's lag-free and instant. moment I put enum in there and save it, I can't type or do anything for about 10-20 seconds when I switch back to the script containing the enum.

not sure if I'm explaining this well

brisk escarp
#

i cant get it filmed (My screen recorders not working)
but here are the two scripts
(Player Controller)


public class Playercontroller : MonoBehaviour
{
    public int maxHealth = 100;
    private int currentHealth;

    private PlayerMovement playerMovement;

    private void Start()
    {
        playerMovement = GetComponent<PlayerMovement>();
        currentHealth = maxHealth;
    }

    //private void Update()
    //{
       // if (Input.GetKeyDown(KeyCode.BackQuote))
       // {
            //MountRideable();
        //}

        //if (Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Space))
        //{
            //playerMovement.Dismount();
        //}
    //}

    ///
    //private void MountRideable()
    //{
       // playerMovement.Mount(rideable);
   // }
    

    // Method to apply damage to the player
    public void TakeDamage(int damageAmount)
    {
        // Reduce the player's health by the damage amount
        currentHealth -= damageAmount;

        // Check if the player's health has reached zero or below
        if (currentHealth <= 0)
        {
            Die(); // Implement game over logic or player respawn here
        }
    }

    private void Die()
    {
        // Implement game over logic or player respawn here
        // For example, reload the level or show a game over screen.
    }

    // Method to heal the player
    public void Heal(int healAmount)
    {
        // Increase the player's health by the heal amount
        currentHealth += healAmount;

        // Ensure that the current health does not exceed the maximum health
        currentHealth = Mathf.Min(currentHealth, maxHealth);
    }
}
#

(Enemy Controller)

public class EnemyController : MonoBehaviour
{
    public float moveSpeed = 2.0f;
    public int maxHP = 50;
    public int damage = 20;
    public float damageRate = 1.0f; // Damage per second

    private int currentHP;
    private Transform player;
    private float nextDamageTime;
    private Rigidbody rb;

    private void Start()
    {
        player = GameObject.FindWithTag("Player").transform;
        currentHP = maxHP;
        nextDamageTime = Time.time + damageRate;

        rb = GetComponent<Rigidbody>();
        if (rb == null)
        {
            rb = gameObject.AddComponent<Rigidbody>();
            rb.useGravity = true; // Enable gravity for the enemy
        }
    }

    private void Update()
    {
        if (player != null && Vector3.Distance(transform.position, player.position) < 10f)
        {
            transform.LookAt(player);
            transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
        }
    }

    private void OnTriggerStay(Collider other)
    {
        if (other.CompareTag("Player") && Time.time >= nextDamageTime)
        {
            Playercontroller playerController = other.GetComponent<Playercontroller>();

            if (playerController != null)
            {
                playerController.TakeDamage(damage); // Deal damage to the player
                nextDamageTime = Time.time + damageRate; // Update the next damage time
            }
        }
    }

    public void TakeDamage(int damageAmount)
    {
        currentHP -= damageAmount;

        if (currentHP <= 0)
        {
            Destroy(gameObject); // Destroy the enemy if its health is depleted
        }
    }
}
teal viper
#

!code

eternal falconBOT
teal viper
teal viper
brisk escarp
#

Fixed it dont worry anymore!

peak plume
#

what should i do to make my character have an animation?

spark trail
spark trail
#

I may have found a temporary solution/workaround, it seems if after I create the enum, I close everything down, then open it again, I can now switch between the enum class and others , without any lag now

#

but if I make a change then save, it lags again until I close it all off lol

#

nevermind, that worked once but not again lol :\

queen adder
#

hello all, i got a big issue with unity, it's not about code but since yesterday, every time i change something like a parameter or a small code, there is an unlimited loading that arrives.. cannot fix, i use unity 2020.3.48f1

#

i have been working for 3 years with it and since yesterday, i'm forced to close it with task manager each time i change something

brisk escarp
frozen mantle
frozen mantle
frozen mantle
queen adder
queen adder
#

it's very random, something it does some times it doesn't.. i have no idea what is happening

hexed terrace
#

#💻┃unity-talk for non-code related issues, that don't fit in any other chan.

Close the project, delete the library folder, re-open

frozen mantle
solemn fractal
#

Hey guys. I create a scriptableobject to control my enemies most common stats etc... But now I have a doubt. to keep it simple, imagine i have 2 enemies. I have a spawn manager object and a script spawn manager. My question is. with 2 enemies I can have 2 prefabs.. but imagine I had 100 enemies, and all different from each other. Would i create 100 prefabs? or if not how can i create something that my spawnManager will be able to spawn all those 100 dif enemies? I cant have 100 prefabs right?

hexed terrace
#

You can do that with 1 prefab, but you would need 100 SO's with the different stats. When spawning you'd assign the SO to the spawned enemy.

solemn fractal
#

hm. So i create 1 prefab called enemy. Ok. I assign the enemySO script there. But ok. I still dont get how I will be able to use instantiate and choose 1 from the other. Lets say. Instantiate(_enemy, transform.position, Quaternion.identity);

#

how here I say which enemy from 1prefab? i am still confused 😂

hexed terrace
#
[SeriliazeField] private MyEnemyComponent _enemy; // assign prefab

MyEnemyComponent enemy = Instantiate(_enemy, transform.position, Quaternion.identity);
enemy.data = scriptableObjectList[index];```
spark trail
#

@teal viper do you know how to disable visuals "Running low background priority tasks" ?

#

It seems this is casuing the lag

solemn fractal
hexed terrace
#

What I gave you is obviously pseudo code, the list is where you need it to be.. probably the spawn manager..

solemn fractal
#

so this list should be of which type?

eager elm
hexed terrace
solemn fractal
#

damn, all of this is so hard 2 days trying to do something that is surely simple but its taking so long just to understand it 🤣 need to be resilient. well anyways thank you !!

minor viper
#

does anyone know how to get your game to your iphone

hexed terrace
#

This is a code channel, #📱┃mobile is where you want .. after you've googled it

long lily
#

hi! has anyone seen this error before? this occurs when I build. -macosx_version_min has been renamed to -macos_version_min

fresh wing
#

Hello, Is it possible to get an image sprite top right coordinates?

slender nymph
long lily
# slender nymph this is still a code channel

I think this relates to code (at least based on google it relates to Xcode issues) But if there is a better forum to post let me know please! Have been struggling with this for weeks

slender nymph
#

then show your code

slender nymph
fresh wing
slender nymph
#

just to confirm, are these Image components or Sprite Renderers?

fresh wing
#

Image

slender nymph
long lily
# slender nymph then show your code

Well it is a lot of code. I think it has to do with somehow not being able to compile on mac but zero issues on pc. Have you seen this error before?

slender nymph
fresh wing
slender nymph
#

that sets the anchor to the upper right no matter what the size of the sprite assigned is

fresh wing
#

Because this will make the parent Image go to the top, not the center

gaunt ice
#

set the pos and anchor of the small image rect tf

fresh wing
#

I only want that small logo on the topleft of the parent Image sprite, witout changing the parent locagion

gaunt ice
#

you dont need to change any setting of rect tf in large image

#

change the child instead

long lily
slender nymph
#

use id:browse to find a relevant channel to ask your question in. this isn't a code issue, which i pointed out yesterday before you'd even provided any details about the issue (other than it being a mac build issue)

fresh wing
slender nymph
#

why have you changed anything on the parent?

fresh wing
#

Here is the parent Image

#

This is the child Image

gaunt ice
#

do you have any layout group and the small image is not child of large image?

spark trail
#

What version of Visual Studios is everyone using?

gaunt ice
#

2022

fresh wing
#

so @gaunt ice do you have any Idea?

gaunt ice
#

have you tried my settings first to see if changing child rect tf still affect parent

fresh wing
#

but when I changed the Image and the image has a different resolution.
the small Image will stuck on the air

fresh wing
#

Found Nothing, still the same reult

regal oyster
#

Hi guys, i need your help : I started Unity today, and i just want to move a capsule arround, i can move it with WASD but the problem is... Jump, a sort of jump work but i can go to infinity (not the goal) i just want a normal jump, jumping and then going back to ground: here's my code :
BTW: I'm really new and i know a lot about c# but +/- nothing about unity.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Windows.Speech;

public class PlayerMovement : MonoBehaviour
{
    // Start is called before the first frame update
    
    public float speed = 4;
    public float jumpForce = 20;
    RaycastHit _hit;
    
    void Start()
    {
        
    }
    
    void Update()
    {
        if (Input.GetKey(KeyCode.W))
        {
            transform.position += Vector3.forward * speed * Time.deltaTime;
        }

        if (Input.GetKey(KeyCode.A))
        {
            transform.position += Vector3.left * speed * Time.deltaTime;
        }

        if (Input.GetKey(KeyCode.S))
        {
            transform.position += Vector3.back * speed * Time.deltaTime;
        }
        
        if (Input.GetKey(KeyCode.D))
        {
            transform.position += Vector3.right * speed * Time.deltaTime;
        }
        
        if (Input.GetKey(KeyCode.Space))
        {
            
        }
    }
}

Thank's in advance

slender path
#

Anyone know how one would make a tree have physics (to fall on the ground) after it gets chopped by the player

summer stump
rich adder
merry spade
#

quick question: Is [SerializeField] a viable option or are there better options to get references?

rich adder
merry spade
#

ok thank you

rich adder
#

if runtime is needed, I'd do whatever DI unity allows (pass reference thru method)

merry spade
#

so getcomponent is also very good?

#

i thought that this is bad

#

but ok

rich adder
#

nah its still slow

merry spade
#

good to know

summer stump
# merry spade so getcomponent is also very good?

It just interates a list of components on the gameobject. If you only have a few, it's actually pretty fast. If it fails to find the component, it's pretty slow

Drag and drop serialized references also take time for the cpu to set up when runtime starts

merry spade
#

ok i understand, but sometimes its the best option right?

summer stump
merry spade
#

serializefield?

rich adder
#

eg. like Collision methods , Triggers, Interactions with rays so on

buoyant knot
slender path
#

I add a RB but it does not take the model with it and phases through the ground

buoyant knot
#

then you didn’t do it right

#

you would need to make a whole new tree object with a rigidbody

#

and if it phases through the ground, you didn’t set its collision properly

#

it would need a collider, model, etc and all that, you know

summer stump
# merry spade serializefield?

That is one way to allow it yeah

Personally, I use GetComponent in awake for most references, but it is sliiiightly slower (almost unnoticeable)

buoyant knot
#

assuming the tree is a part of the terrain

buoyant knot
#

if the tree was already its own gameobject, then you’d need to alter it, and make a stump or something like that

summer stump
merry spade
#

what do you mean?

summer stump
merry spade
#

but then there is no reference?

summer stump
merry spade
#

ah wait

#

we were talking about different things

#

AHHH

#

now i understand

summer stump
merry spade
#

yes

#

i was too but i didnt consider using public

#

thats smart

#

xD

#

never thought about it

summer stump
merry spade
#

yeah

#

true

quiet dune
#

Hi, I have a class with a static variable that is initialized in the awake() method. Whenever i pause the runtime, change something in the code, and resume the runtime. Unity recompiles and the variable looses its value. Why is this happening?

summer stump
#

You should be stopping

rich adder
#

changing code at runtime will just give you missing script errors

summer stump
polar acorn
rich adder
quiet dune
#

Thanks guys, makes sense. Honestly i was supprised, that unity handled "hot reloads" if thats the term, pretty well so far and got used to it, because it allowed me to see instant results to changes i was making. Just not doing that would certainly solve the issue 😏

rich adder
quiet dune
#

I even changed conditions for if statements and removed code fragments and stuff like that which would take effect on a running game. I thought that to be a nice and convenient feature 😄

rare basin
#

Why is

Debug.Log("Local Y: " + letterDescription.transform.localPosition.y);

printing different values from what i see in the inspector? it's printing -500 and the inspector value is

polar acorn
rare basin
#

Ow

#
    private void StartLetterScrolling(float desiredYPos, float duration)
    {
        scrollTween = letterDescription.rectTransform.DOMoveY(desiredYPos, duration).SetDelay(letterStartScrollDelay).OnComplete(() =>
        {
            scrolled = true;
            OnScrolled?.Invoke();
        });
    }
#

Im using DOTween to move a text

#

on Y axis (just scrolling it up)

#

i thought that doing DoMoveY on rectTransform will figure this out for me

#

i see that there is DOAnchorPosY

#

i'll give it a try

rich adder
#

yea use DOAnchorPosY for rect

rare basin
#

works flawless now

#

thanks

#

just to confirm

#

there is no such thing as local anorched pos?

rich adder
#

afaik anchored pos is kinda like the local pos for screen space

eternal needle
polar acorn
quiet dune
agile trail
#

Very beginner question here but how do I change the speed of my animation as the sample button does not seem to exist my my animator window?

soft thistle
#

Have a question, its better to have 10 custom scripts with the function update, or only one update function with all things inside ?
only for performance reason

rich adder
fossil drum
rich adder
#

I have all my other scripts hook onto this 1 gloabal Update usually

polar acorn
somber kindle
#

Hello is it possible to get an Image Source from an Image Component?

rich adder
#

cause its just a sprite/texture ?

somber kindle
rich adder
#

var mysprite = myImgcomponent.sprite

somber kindle
rich adder
#

probably

#

not sure how, I think you can use the bounds size and some math

silk night
#

Yeah position + bounds would be able to do that

#

!code

eternal falconBOT
finite star
#

congrats!

quiet dune
#

Is value = calculation(); if(value) more performant in any way than if(calculation())? I'm thinking in way of memory allocation/garbage collection

silk night
#

otherwise it doesnt really matter

quiet dune
#

Nah, I would just assign the value for readability and debugging

polar acorn
#

I think the second one actually looks more like the first when compiled

quiet dune
polar acorn
#

Nothing here is physics though, it's teleportation

silk night
#

Oh nvm, my fail

#

for some reason i thought it was using force at the bottom

unique laurel
#

what does this mean

summer stump
#

You cannot use it

frosty hound
unique laurel
#

oh ok

frosty hound
#

You have to use PlasticSCM (the version control package)

#

Or use something third party like git and save yourself the headache.

unique laurel
#
using System.Collections.Generic;
using UnityEngine;

public class SimpleMovement : MonoBehaviour
{

    public float movementSpeed = 5f;

    public Rigidbody2D rb;

    Vector2 movement;

    //update is called once per frame
    void Start()
    {
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");
    }

    private void FixedUpdate()
    {
        rb.MovePosition(rb.position + movement * movementSpeed * Time.fixedDeltaTime);
    }
    // Update is called once per frame
    void Update()
    {
        
    }
}
#

is thier a issue with the code

#

the character refuses ot move

silk night
#

Check the values in the inspector

#

Oh and you just set the movement once on start

#

set it repeatedly in update

summer stump
green copper
#

what do I need to do during or after Instantiate() to let me manipulate the object afterwards with more code?

silk night
unique laurel
green copper
#

oh, so like GameObject thing = Instantiate(stuff);

summer stump
summer stump
unique laurel
silk night
#

oh nvm you edited it

polar acorn
unique laurel
summer stump
summer stump
green copper
# silk night yes

is there a way to do it so that the code runs before the Start() function on the new object runs? Or is that default behavior?

summer stump
silk night
green copper
#

I need to set a variable, 'size' of one of the new objects, and 'size' is used in a function in Start() to change the scaling

silk night
#

He wants code under instantiate to run before start

polar acorn
green copper
#

so

Instantiate(thing)
thing.size = 2
[Thing's Start() uses the size to affect scaling before it fully exists]

summer stump
polar acorn
#

Start doesn't run until the start of the next frame

green copper
#

So this should function?

polar acorn
summer stump
unique laurel
#

still doesnt want to move

summer stump
silk night
unique laurel
#
using System.Collections.Generic;
using UnityEngine;

public class SimpleMovement : MonoBehaviour
{

    public float movementSpeed = 5f;

    public Rigidbody2D rb;

    Vector2 movement;
    
    void Start()
    {
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");
    }

    private void Update()
    {
        rb.MovePosition(rb.position + movement * movementSpeed * Time.fixedDeltaTime);
    }
}
polar acorn
summer stump
#

Not what we said

#

Put the rb.MovePosition back in FixedUpdate

polar acorn
summer stump
#

Move the INPUT into Update

Start only runs once. How would you get input during the game when it is in start?

green copper
polar acorn
polar acorn
summer stump
polar acorn
#

Just use that component as the reference and save the GetComponent call

polar acorn
green copper
#

or do I need to also put a getcomponent in the instantiate somewhere?

summer stump
summer stump
#

You don't really want GameObject references very often. Just make the prefab the type you'll use most

polar acorn
#

Essentially, if you ever need the prefab to do more than just exist you shouldn't be using GameObject

summer stump
polar acorn
summer stump
unique laurel
#

i changed start to update

    {
        movement.x = Input.GetAxisRaw("Horizontal");

        movement.y = Input.GetAxisRaw("Vertical");```

seems to have worked
green copper
polar acorn
polar acorn
#

You might have to drag the object back in since it's technically a new field you've made by changing the type

#

but other than that, nothing changes

summer stump
green copper
#

That broke the collision system with the projectiles for some reason....

polar acorn
green copper
#

no errors, the laser now just phases through the rock

#

collision was detected with OnTriggerEnter2D

#

and if collider.gameObject.tag == "asteroid"

polar acorn
green copper
#

asteroid still has a tag

#

Oh, wait

#

I think I just forgot to save my changes

#

is working fine on second attempt

#

hate it when that happens