#šŸ’»ā”ƒcode-beginner

1 messages Ā· Page 596 of 1

trail heart
#

How?

hot laurel
#

sounds like the zombie chase is in wrong axis

void dawn
visual linden
#

Start by sharing the code in question :)

#

!code

void dawn
#

ok

eternal falconBOT
bitter apex
#
    if (Input.GetAxis("Mouse ScrollWheel") < 0f ) // forward
        {
            Camera.main.orthographicSize++;
        }
        else if (Input.GetAxis("Mouse ScrollWheel") > 0f ) // backwards 
        {
            Camera.main.orthographicSize--;
        }

Currently I have this as my code, but it seems to be really.. temperamental? I'm trying to "zoom out" of my 2d game, but I have to scroll down on my mouse anywhere between 5 - 50 times just for it to scroll out

#

I'm not sure why, either, could anyone please give me some advice

wintry quarry
void dawn
bitter apex
#

thank you, It turns out all I had to do was change it from being in FixedUpdate() to Update(), i guess fixedupdate works differently to how i expected it to šŸ—æ

wintry quarry
grand snow
bitter apex
#

oh lovely. thank you

bitter apex
grand snow
#

@bitter apex and to make it go backwards do (1f - Input.GetAxis("Mouse ScrollWheel")) * multiplier

#

no wait it should be axis * -1 mb i forgot its from -1 to 1

wintry quarry
#

that's not right - you'd just multiply by -1

grand snow
#

haha yea i just realised

#

@bitter apex i was wrong, correction above ^

polar acorn
#

Did you take the NavMesh surface off of the zombie like we said yesterday

polar acorn
void dawn
polar acorn
polar acorn
#

Okay and did that solve the problem

void dawn
#

let me try

#

a warning and an error

Failed to create agent because there is no valid NavMesh this is the warning

this is the error
MissingComponentException: There is no 'Animator' attached to the "ZOMBIE" game object, but a script is trying to access it.
You probably need to add a Animator to the game object "ZOMBIE". Or your script needs to check if the component is attached before using it.
UnityEngine.Animator.SetBool (System.String name, System.Boolean value) (at <9b89611000504a9585efec19be4faf3b>:0)
ZombieAI.Update () (at Assets/scripts/Zombie AI.cs:60)

well i did create an empty child to put the animator in

polar acorn
void dawn
#

you know what , i think before i go on with this project i should do a unity basics course and a c# basics too

polar acorn
#

Yes, absolutely

#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

inland kettle
#

https://codeshare.io/g8koNY

why is it that even though I set previousItemX as inactive, it still is active when I play? I wanna be able to only have one object from each category active

polar acorn
inland kettle
rich adder
#

lord..

inland kettle
#

ā˜ ļø

polar acorn
# inland kettle

So, those first 9 things - are those prefabs or objects in the scene

#

when you click on them, what highlights

polar acorn
#

You're disabling a prefab

inland kettle
#

No I’m disabling the Actual (item) s

#

Those prefabs are destroyed in update

#

Those work

polar acorn
inland kettle
# inland kettle

Top 1 to hair 3 are prefabs, actual top 1- actual hair 3 are game objects

polar acorn
#

Ah, wait, I see, you've got separate variables for the prefabs and the instances.

inland kettle
#

Yes

polar acorn
#

This is part of the reason you should be using collections, easier to read

inland kettle
#

Will take note for future projects, still quite new to this

polar acorn
#

They're re-activated by the wearClothes method, which is being called from somewhere else, for now, just put return; as the first line of it so the rest of the function is skipped. Do they all start up deactivated then?

inland kettle
#

I thought you can’t put return in void functions?

inland kettle
#

Whaaaat

rich adder
#

it just returns early without any value

inland kettle
#

Ohh

inland kettle
polar acorn
#

Oh, right

#

Do that

#

(Definitely learn arrays)

inland kettle
#

I’ve learnt arrays, just didn’t think of using them lols

scarlet skiff
#

i dont get it are these not the exact same return type? whats the issue

rich adder
#

yeah once you're adding numeration to your variables, its def time for an array

inland kettle
polar acorn
polar acorn
inland kettle
polar acorn
#

We want to disable these functions and see if Start is actually deactivating things

swift crag
polar acorn
#

so we're removing the code that reactivates them

inland kettle
#

Ohhh

swift crag
#

Is that a completely different State?

scarlet skiff
inland kettle
polar acorn
inland kettle
#

Yes

swift crag
#

rather than into a list of IState?

polar acorn
# inland kettle Yes

So, it seems one of those WearClothes functions is being called on startup, which is why there are some that are active on start

rich adder
swift crag
polar acorn
humble hound
#

cant start it

#

getting 404

swift crag
#

paste the exact URL you're trying to access

rich adder
#

clear your browser cache

scarlet skiff
humble hound
#

its working now rebooted router

rich adder
#

a nice flush of DNS works too

#

unity has changed some links around and caused massive headaches

inland kettle
swift crag
#

Make sure that you have the correct State

polar acorn
inland kettle
#

Ohh sorry I should’ve worded it better

swift crag
polar acorn
rich adder
#

tuple is just a lazymans struct anyway

polar acorn
inland kettle
#

So when I click an item it activates it in the scene, and it stores the previous activated item in previousItemX, which I then deactivate. Problem is that’s not working

polar acorn
inland kettle
#

Sorry, what’s logging?

rich adder
inland kettle
#

Oh debug

inland kettle
#

Okay

heady pagoda
#

im working on this game where theres this like little companion that follows me around and it pretty much works but when i actually start the game the character follows me but also flys in my direction. When i add a rigidbody it somewhat fixes it but the character just starts glitching out and "thrusts" into me. how do i fix this?

rich adder
#

also send !code as link

eternal falconBOT
heady pagoda
# rich adder how can we know if you don't show the code

oops also heres the tutorial i used https://youtu.be/zssU0MZcIx8?si=xJGffJDdmK8bH82B

using UnityEngine;

public class AiFollow : MonoBehaviour
{
   public GameObject ThePlayer;
   public float TargetDistance;
   public float AllowedDistance = 5;
   public GameObject TheNPC;
   public float FollowSpeed;
   public RaycastHit Shot;
    // Update is called once per frame
    void Update()
    {


        
        transform.LookAt(ThePlayer.transform);
        if(Physics.Raycast(transform.position,transform.TransformDirection(Vector3.forward), out Shot)) 
        {
            TargetDistance = Shot.distance;
            if(TargetDistance >= AllowedDistance)
            {
                FollowSpeed = 0.005f;
                TheNPC.GetComponent<Animation>().Play("Jogging");
                transform.position = Vector3.MoveTowards(transform.position, ThePlayer.transform.position, FollowSpeed);           }

                else
                {
                    FollowSpeed = 0;
                    TheNPC.GetComponent<Animation>().Play("Breathing");
                }
        }
    }
}

#JIMMYVEGAS In this Mini Unity Tutorial we show you how to create a script which will make an NPC follow you like a companion.
✦ Subscribe: https://goo.gl/gidCM5
✦ Patreon: http://patreon.com/jimmyvegas/
✦ FREE Assets: http://jvunity.com/
✦ Facebook: https://www.facebook.com/jimmyvegas3d/
✦ Twitter: https://twitter.com/jimmyvegas17/

----------...

ā–¶ Play video
wispy wraith
#

!code

eternal falconBOT
rich adder
#

anyway moveTowards is probably not a good way to implement this. either way, seems your Y axis aren't level

#

if player origin is at 0, 5, 0 and the companion is at 0, 2, 0 it will float to 0,5,0

#

you probably want to use a Navmesh agent though,

#

if you ever encounter a wall between you and your companion it will just phase through the wall

slow knot
#

uh how many lines on average should an AI be

rich adder
#

whatever amount required

slow knot
#

alright was just asking where the line goes between rididucilously long script and normal script

#

im making an AI for my game (my first game that is)

#

its currently like 200 lines

#

202 actually

#

but aight thanks

rich adder
#

the line count only matters for your readability it makes 0 difference in the end code

heady pagoda
slow knot
#

to make my code more readable, do i place all variables of one sort, for example public ranges and the privates next to each other

#

Becasue right now my code is a complete mess with functions everywhere

rich adder
#

tbh this whole thing is a mess, just use a navmesh agent

#

you will have a better companion follower that can actually avoid obstacles

rich adder
heady pagoda
#

i can give it another try

rich adder
#

those are just visuals

#

you can literally slap anything on navmesh agent and it will move it

#

navmesh agent is just controlling the transform moving it on flat mesh baked areas

heady pagoda
#

i only have this vid from the nav mesh version and the companion just went flying

i gave up on it and did the thing i have currently but i can try again

heady pagoda
rich adder
#

why does navmesh agent have surface on it?

#

navmesh surfaces are powerful but you dont put them on moving agents..

heady pagoda
#

the tutorial i watched was super old and it had a nav mesh agent and those things used to have the bake thing but then they removed it from the agent no?

#

so i just added the surface to bake it

rich adder
#

things have changed yes

#

you add navmesh component then you bake it yes, you keep it on a static ground usually unelss you know what you're doing with moving objects.

rich adder
# heady pagoda so i just added the surface to bake it

I suggest you go through this
https://youtu.be/SMWxCpLvrcc

The AI navigation system in Unity allows non-player characters (NPCs) to move intelligently through a game environment by calculating and following optimal paths and avoiding obstacles.

In this video, you’ll learn how to get started by setting up a NavMesh surface and how to set up the AI Navigation system package in Unity 6.

More resources:
...

ā–¶ Play video
rich adder
#

this is from unity so you know its good

wanton epoch
#

Does anybody by any chance know of a tutorial to add a character with animations to a first person game with the ability to see your hands and feet? I am currently using just a capsule with my own player movement script. But I cant seem to figure out how to switch the capsule to a character model while also allowing it to move with my player script.

rich adder
#

one shouldn't impede the other

#

so idk what this means

how to switch the capsule to a character model while also allowing it to move with my player script.

#

unless you have animator set to drive root move transforms the animations are just visuals they don't touch movement

#

apply some mixamo animations or something to a child object that has the humanoid rig
just make sure your animator states match your script actions.. if your script is moving your controller with speed then start moving animation etc.

frigid sequoia
#

If I want to pass a enum parameter to a method from another class, where do I have to declare the enum?

frigid sequoia
#

In the class calling the method, in the class that has the method or in both?

ripe shard
rich adder
#

if you nest the enum definition in the class then you need to preceede it with that class if you access it from else where

echo ruin
#

If you have an enum you should be able to just put it in the parameter

rich adder
#

Class1.Enum.
instead of Just

#

Enum

frigid sequoia
#

Mmmm, I see

#

I basically want to make like a script that is basically a status effect that other classes can generate upon different targets, and I wanted to have like a enum to identify the stacking method

#

So I guess I should have the enum in the class that generates the status, and reference that on the status itself

rich adder
#

i always put enums in their own files

timber tide
#

So, if you make the enum inside of the class then you need to append the class type onto that enum

echo ruin
#

You can just make an empty script and just have the enum there. Then any class can call it

timber tide
#

if you have a namespace, you can toss it onto that and use it everywhere in that scope without having to append the class type onto it

#

well, you can also do without a namespace inside of a 'global' scope, but I suggest always including a namespace anyway

rich adder
#

basically if its defined in another class you are doing

public class Foo{
    public enum MyEnum { x, y, z }
    public void MethodWithEnum(MyEnum val){
    }
}
public class Bar{
    private Foo foo = new();
    void Method(){
        foo.MethodWithEnum(Foo.MyEnum.x);
    }
}```
timber tide
#

Should only be using nested enums within the class itself anyway. If it's being used elsewhere then stick it on a more outer scope

frigid sequoia
#

So I should be doing this???

#

Or should I have a more general access?

rich adder
timber tide
#

What's the enum called and what does it correspond to

frigid sequoia
#

They need to know what the enum means

#

The enum is called in the initialization of a status effect, to check what it should do in relation to other status effects

#

In like, if they are the same, do they just happen togheter? Does the more recent one overrides the other? Does it reset the duration of all status of the same name?

timber tide
#
namespace ProjectName
{
  //UtilityScript.cs
  public enum StatusEffect
  {
    Blind,
    Freeze,
  }
}

namespace ProjectName
{
  public class Skills
  {
    public StatusEffect StatusEffect;
  }
}```
Simplified idea
fleet venture
#

why can i not get a gameobject from a scrollview?

timber tide
#

Ideally you do split the namespaces up a bit more, but that can be a little confusing unless you've the idea how to group everything.

#

Like I would have a Entity namespace, Stats namespace, ect

frigid sequoia
#

So I make those enum in like separated scrip on the namespace of the whole project?

fleet venture
#

its not a thing

#

idk why

rich adder
rocky canyon
#

u got a class named Props?

fleet venture
#

oh

fleet venture
timber tide
fleet venture
#

its the field

#

so how do i do it then

#

do i make it a GameObject type?

frigid sequoia
timber tide
#

Yeah, until you install a plugin and they have the same class names as you. WHICH they will have their own namespace unless they want to piss people off

rich adder
fleet venture
#

ok

rich adder
#

put your item in the slot and you're done

fleet venture
#

ye

#

ok

frigid sequoia
timber tide
#

your classes become wrapped in the namespace

fleet venture
#

ok diff question why can i not see my game

#

nvm

#

im stupid

#

i was zoomed in

frigid sequoia
timber tide
frigid sequoia
#

Doens't it warn you when you do that?

timber tide
#

It does, but if Unity didn't wrap it in Unity.UI namespace then you couldn't make a class called Image yourself in that global space.

fleet venture
#

oh eew

rich adder
fleet venture
#

unity uses an old c# version?

#

oh god thats 4 versions older than what im used to

rich adder
#

when core CLR drops we will have modern .net & c#šŸ¤ž

fleet venture
#

nice when will that be

rich adder
#

hopefully unity 7

wintry quarry
#

unknown

#

probably in 1.5-2years

fleet venture
#

how often does a unity version drop

#

ah ok

frigid sequoia
#

So.... something like this would be fine to use?

timber tide
#

Well, the namespace would include all classes that want access to those enums

#

Like as an example above if I had a Skill namespace then I'd include all scripts that deal with my abilities and need to share those enums among each other

frigid sequoia
#

So... in any class that I use the using ProjectGeneralEnums, it would become wrapped by the namespace then?

timber tide
#

Any class that wants to use those enums you'd wrap into the namespace, otherwise you have to #Include 'Using' it on that file or explicitly state where those enums comes from

wintry quarry
#

I think of namespaces this way:

A namespace is just part of the type name. Your full type name is ProjectGeneralEnum.StackingMode But if you put using ProjectGeneralEnum you can just write the short version StackingMode

#

So when you want to use that enum you either write the full name ProjectGeneralEnum.StackingMode or you do using ProjectGeneralEnum so you can just write the short version StackingMode

timber tide
#

And if it's all in the same namespace then you don't even need to use 'using'

frigid sequoia
#

Oh, ok

#

I am not very used to namespaces tbh

timber tide
#

Wrapping enums into its own namespace is something I've seen too, but I like to group classes who use those enums together.

frigid sequoia
#

So I basically just created a thing I can call from anywhere like any other method implemented in base unity right?

timber tide
#

As what you provided, if you don't wrap anything else in that namespace then at the top of the scripts that need to use those enums you'd have

using ProjectGeneralEnum```
As stated by PraetorBlue
wintry quarry
#

The only barrier to that would be if they're in different assemblies, which is a whole nother topic

timber tide
#

I just stink at naming stuff and I will run into reusing enum names, so without namespaces it wouldn't be possible

chrome apex
#

so I have the same error as yesterday, see screenshots with error and code:

#

I don't understand why. I referenced the class and the object in the inspector

wintry quarry
chrome apex
#

but there is

wintry quarry
#

so it's clear you would get an error writing Play.play here

polar acorn
wintry quarry
#

no there isn't

chrome apex
#

ok I will show you the script for that one

wintry quarry
#

your variable is a GameObject

#

not whatever script you're about to show us

chrome apex
#

omg I'm an idiot

wintry quarry
#

if you want to reference a script, you need to use that script's class name, not GameObject

chrome apex
#

I was referencing the object, not the class

#

that's why

#

sorry, I'm just a little bit mentally impaired

frosty hound
#

Didn't this happen yesterday?

chrome apex
#

yes it did lmao

#

yesterday it "fixed itself", maybe that's what happened

#

that's what happens when you name them the same thing

void dawn
#

so i tried making a gun that the player can pick from the ground and use it , the problem ? the player just walks into the gun like it dosent exist

#

i will show you the code soon

polar acorn
void dawn
#

hang on

polar acorn
#

Put a log in the top of OnTriggerEnter and log other.gameObject.tag and see what logs

void dawn
#

sorry if this sounds stupid but you want me to do this on the console right ?

polar acorn
#

That is where logs tend to go

dreamy rose
#

guys i have a question how do i add custom meshe to my player

polar acorn
swift crag
dreamy rose
dreamy rose
#

its like i put the camera where it is and its like MILES OFF

polar acorn
dreamy rose
#

my fault

#

its currently 1 am

polar acorn
#

Does your mesh contain a camera

dreamy rose
#

no

polar acorn
#

If so, remove it

polar acorn
dreamy rose
polar acorn
#

no

dreamy rose
#

uh okay i can try screen recording

#

jsut let me set it back up

swift crag
#

you're asking a series of questions that make no sense

lone thorn
dreamy rose
lone thorn
#

cus its our project

#

right so we have a player model from blender

swift crag
#

Are you trying to import a rigged model into Unity to use as a player model?

lone thorn
#

an fbx rigged and everything

lone thorn
#

what we’re having trouble with is adding a custom mesh

#

and when we just use the base fbx

swift crag
#

i don't know what "custom mesh" and "base fbx" means here

lone thorn
#

the camera doesn’t allign with its position

lone thorn
polar acorn
swift crag
#

Why do you need to add extra mesh renderers?

#

Are you trying to, say, put a hat on the player?

lone thorn
#

it didn’t work out

swift crag
#

Explain your actual problem, not your attempted solution

lone thorn
#

it turned out so weird

polar acorn
#

Cameras don't do anything on their own. If you want it to align with something, you have to actually do something with it

lone thorn
#

but it seems detached from the player

#

its really hard to explain

polar acorn
#

Maybe show a screenshot or something

dreamy rose
swift crag
#

you need to coherently explain what you're trying to accomplish and what is happening

#

So far you've just said "custom mesh", but I have no clue what that actually entails

#

are you trying to completely replace the player model?

polar acorn
#

There are no voice channels in this server

lone thorn
swift crag
#

are you trying to attach an object to the player?

#

Then you haven't tried to explain.

#

Tell me what you want to make your game do.

#

Do not include anything technical whatsoever.

#

Simply describe what the end-goal is.

lone thorn
#

we want the camera to be attached to the player in a first person perspective

dreamy rose
#

does that make more sense

swift crag
lone thorn
#

and the capsule

#

the camera works perfectly

#

but the model that we use

#

the we made

#

the camera is misaligned

polar acorn
#

Is your model actually in the right place

dreamy rose
lone thorn
swift crag
#

ensure that its local position is zero, yes

dreamy rose
polar acorn
# lone thorn elaborate

If your camera is pointing at a position, is that position where you'd expect it to be on the mesh

polar acorn
#

like, if you want it to point at the center of the object

#

is the center of the object where the camera is set to follow

lone thorn
#

okay so if i move the camera to the player’s head it’s not even attached to him

#

we see it from a third person pov

dreamy rose
#

yeah

polar acorn
dreamy rose
#

how? it says the camera is on the model

swift crag
#

Did you parent the camera to the model prefab directly?

slender nymph
#

obligatory "use cinemachine"

lone thorn
#

yes

polar acorn
#

Then move the camera

swift crag
#

That's going to make the camera sit in a fixed location relative to the model prefab object

lone thorn
#

ohh wait

swift crag
#

It's not going to care about anything that the model is doing

lone thorn
#

the camera

swift crag
#

put the camera in the correct place instead of the wrong place

lone thorn
#

is in a parent object called camera holder

#

the player is a separate family

dreamy rose
#

yes\

polar acorn
#

So we don't need to ask a bunch of questions about what objects are where

dreamy rose
#

alright give me a seconjd

polar acorn
# dreamy rose

Okay, so, playerCam is not a parent or child of the mesh at all

dreamy rose
#

yeah according to the video it makes it less buggy? if it would help i could send you the video i followed

polar acorn
#

So, it seems like you just want to move either it or the mesh so they're where you want them to be

swift crag
#

note that CameraPos is pointing backwards

lone thorn
swift crag
#

the blue arrow is the forwards direction for that object

lone thorn
#

we move the camera slightly frontwards it goes a million miles front

polar acorn
#

I don't even know what cameraPos is doing

#

It has no scripts

#

and no one's posted any code

#

so I have no information as to what that object does

dreamy rose
polar acorn
dreamy rose
#

could i send you the video so you could see what i mean

#

the video is very short

polar acorn
# dreamy rose

Okay, so you want the camera pointed out of the back of this guy's head

dreamy rose
#

i flipped it

#

it did nothing

polar acorn
#

How about show the !code of what moves the camera

eternal falconBOT
dreamy rose
#

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

public class PlayerCam : MonoBehaviour
{
public float sensX;
public float sensY;

public Transform orientation;

private float xRotation;
private float yRotation;

// Start is called before the first frame update
private void Start()
{
    Cursor.lockState = CursorLockMode.Locked; 
    Cursor.visible = false;
}

// Update is called once per frame
private void Update()
{
    float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;
    float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;

    yRotation += mouseX;

    xRotation -= mouseY;
    xRotation = Mathf.Clamp(xRotation, -90f, 90f);

    transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
    orientation.rotation = Quaternion.Euler(0,yRotation, 0);
}
eternal falconBOT
dreamy rose
#

huh?

polar acorn
#

The bot tells you how to post code

dreamy rose
#

alright

north kiln
tulip stag
#

I wanna write code that parses this into a Json and parses Json into this. I know that SO can't be parsed into Jsons— should I turn it into a Monobehaviour, or should I add a "dummy" Monobehaviour to parse this into and then parse it into a json and vice versa?

dreamy rose
wintry quarry
#

MB or SO will make it more complicated

tulip stag
#

What's POCO, sorry?

wintry quarry
#

plain old C# object

#

just a regular class like you have

dreamy rose
wintry quarry
#

oh sorry

#

you have an SO right now

polar acorn
tulip stag
wintry quarry
#

put all that dataq in a regular serializable class

polar acorn
wintry quarry
#

and just make that as a field on the SO

dreamy rose
polar acorn
# dreamy rose

So, every frame, you teleport the camera to this object's position, and you rotate the camera based on the mouse

swift crag
dreamy rose
#

i still dont see why its not worki ng?

polar acorn
#

Meaning the end result is, you should have a camera that is fixed inside of this mesh's head and spinning around as you move the mouse

swift crag
#

Aha

polar acorn
swift crag
#

I figured out what the actual problem is

#

The player model isn't rotating.

slender nymph
swift crag
#

A capsule is radially symmetric, so it was not possible to tell that the capsule wasn't rotating

dreamy rose
swift crag
#

The object itself can still be serialized meaningfully.

polar acorn
dreamy rose
tulip stag
dreamy rose
#

im not sure if this is what you meant but here

polar acorn
#

Okay, so, if there is no other code involved in movng the camera, with what you've shown, there is no way that this code could result in the camera angle you showed

#

Which object has PlayerCam and MoveCam

dreamy rose
polar acorn
#

It will always be this many units away from the camera position in the player:

#

Which is to the left and in front, and slightly above

dreamy rose
#

wait so i just need to change the position of that?

polar acorn
dreamy rose
#

sorry i dont really understand

dreamy rose
#

okay

#

let me try

polar acorn
#

Since you are moving the parent object to the cameraPos object, this object's position will be the offset from that the camera is in

#

this had nothing to do with the model

dreamy rose
#

woooooooowwwwwwww okay

#

i slightly understand now

polar acorn
#

The position you see in the inspector is how far away the object is from its parent

dreamy rose
#

im sorry if im a bit slow

polar acorn
dreamy rose
#

the player cam

#

you said its offset right?

polar acorn
#

Yes

#

Offset by exactly this much

#

It is that many units away from this

dreamy rose
#

so i should make allt he positions 0?

polar acorn
#

X is left/right
Y is up/down
Z is forward/backward.

So, the camera is 2.82 units to the left of the guy's head, 1.47 units above the guy's head, and 2.87 units in front of the guy's head

polar acorn
dreamy rose
#

wow

#

okay

#

yeayh it worked

polar acorn
#

If this object's position were 0,0,0 then it would be at 0 units to the left, 0 units above, and 0 units in front

#

which would mean it's at that object's position

dreamy rose
#

yeah i understand now

#

thanks alot

void dawn
#

how do i make a weapon switching system , you know like most fps games

swift crag
#

that depends quite a bit on what a "weapon" even is in your game!

polar acorn
#

Change out the model you're rendering, and what kind of prefab your gun shoots

frigid sequoia
#

Okay, I know this is like a pretty rough ask, but since this feels like extremely hard to test out for all cases. I would love if some of you guys could check this to see if I made like some kinda of superobvious msitake https://pastecode.io/s/zz6o2woj

swift crag
#

oh man, status effect stacking

#

i remember doing this extremely wrongly about eight years ago

void dawn
swift crag
#

does your game have any weapons at all right now?

#

at its most basic level: get rid of the current weapon, then create a new weapon

timber tide
#

Status effect stuff is hard

#

You'd think coroutines be fine but sometimes you want to remove specifics and that's such a pain

swift crag
#

It's the stacking of a mixture of different effects that gets really annoying

#

when they have different rules (possibly multiple rules on different instances of the same effect)

timber tide
#

Well, having a good GDD fixes a lot of problems too ;p

#

knowing me I don't know what the heck I want most of the time

void dawn
frigid sequoia
swift crag
#

perhaps you can start by just completely throwing out the pistol

timber tide
polar acorn
#

what scripts, assets, etc. make up the whole of "Pistol"

void dawn
polar acorn
#

So, it sounds like you just wanna disable the pistol model and enable the rifle model. Then do whatever your script does to be a different weapon

void dawn
#

yes and be able to swap for other guns the player find in the game

void dawn
pure drift
#

!code

eternal falconBOT
pure drift
polar acorn
pure drift
#

thank you

void dawn
slender nymph
#

fun fact about paste.mod.gg, you can add multiple files to a single post

void dawn
#

i did not know that

slender nymph
#

also did you ever bother confirming that OnTriggerEnter is being called?

void dawn
lapis yew
polar acorn
lapis yew
#

nah i push it directly to an active Command panel

nimble apex
#

i have made a custom button on the inspector, this button is the only thing doing ,beware this is SOLELY on editor mode only, it will NEVER be in runtime mode:

  1. clean up collection A
  2. instantiate linked prefab, not unlinked instance
  3. populate collection A with those prefabs
  4. populate collection B with collection A

all this steps are in a single function, and it wont be called by anything in runtime or editor mode unless inspector button is pressed

#

now i gonna show u guys how i populate both collection

#

this is collection A , A is a Dictionary<GameObject,contentType>

    private Dictionary<GameObject,contentType> allGameObjects = new();

    public void RebuildContent()
    {
        allGameObjects.Clear();

        if (hasSubTitle)
        {
            GameObject spawnedObj = Instantiate(prefabs[0], transform);
#if UNITY_EDITOR
            PrefabUtility.ConvertToPrefabInstance(spawnedObj, prefabs[0], new ConvertToPrefabInstanceSettings(), InteractionMode.AutomatedAction);
#endif
            allGameObjects.Add(spawnedObj, contentType.Subtitle);
        }

        foreach (contentType element in spawningElement)
        {
            GameObject spawnedObj = Instantiate(prefabs[(int)element], transform);
#if UNITY_EDITOR
            PrefabUtility.ConvertToPrefabInstance(spawnedObj, prefabs[(int)element], new ConvertToPrefabInstanceSettings(), InteractionMode.AutomatedAction);
#endif
            allGameObjects.Add(spawnedObj, element);
        }
    ..... <- populate collection B```
#

this is collection B , i made "a list of lists" , because i need to show it on inspector i need to chain them as serializable

[Serializable]
public class AllStepObj_Value
{
    public List<GameObject> Objects;
}

[Serializable]
public class AllStepObjMap
{
    public List<AllStepObj_Value> Steps;
}```
#

this is how i populate it

        int counter = 0;
        
        objMapper = new();
        objMapper.Steps = new(new List<AllStepObj_Value>(){});
        objMapper.Steps[0].Objects = new();

        foreach (GameObject element in allGameObjects.Keys)
        {
            objMapper.Steps[0].Objects.Add(element);
        }```
#

all of these scripts did not involved "execute in edit mode", as they are fully driven by inspector button events

#

by pressing the button, it will do something like this on inspector

#

objMapper (collection B) , is actually populated like the code

#

but if i ever move to other scene and come back, all stuff i populated on objMapper will disappear

#

why tho?

#

assigning it by hands , dragging objects will reserve across scene, but not code ?

slender nymph
#

did you mark the object as dirty?

nimble apex
#

dirty?

#

i think i havent?

nimble apex
#

ohhhhh

#

ty i will look at it

scarlet skiff
#

whats this?

slender nymph
#

seems like a visual studio issue not related to unity

nimble apex
#
            if(GUILayout.Button("Rebuild UI"))
            {
                Undo.RecordObject(parent, "populate objMapper");
                parent.OnRebuild();
                PrefabUtility.RecordPrefabInstancePropertyModifications(parent);
            }```
#

i used undo instead of setdirty, it seems better

#

this is on my custom editor script

#

worked , ty šŸ‘

last owl
#

Is there any reason an if statement with the condition that a certain boolean is true can evaluate to true but nothing inside the if statement actually runs? I'm so stumped, I've put debug logs everywhere and everything up until the boolean changing from false to true happens, but nothing inside the if statement runs. I've checked and there are no spelling errors.

frigid sequoia
#

Why can I not assign this?

#

Like it doesn't slot

slender nymph
#

are you attempting to drag a scene object into a prefab?

frigid sequoia
#

I am trying to assign a component of a child inside the prefab into a script on the prefab

slender nymph
#

actually have you saved your code? because the slot shows TextMeshPro rather than TextMeshProUGUI

frigid sequoia
#

I did, yeah

swift crag
#

Perhaps you have a compile error.

#

The type name is, indeed, wrong

frigid sequoia
#

Oh, unless it's not compiling cause I have an error in other script wait

swift crag
#

(also, you can generally just use TMP_Text)

nimble apex
#

textmeshpro is different from UGUI, one is solely UI , one can be instantiated in world space

slender nymph
swift crag
#

TextMeshPro and TextMeshProUGUI have largely the same interface

#

i'm actually not sure what would differ from the outside

nimble apex
#

they are very close

swift crag
#

(hence why I always just use TMP_Text)

nimble apex
#

and then u can use TMP_Text

swift crag
#

that's a given for any textmesh pro type

nimble apex
frigid sequoia
#

Doing a .Clear() on a dictionary is pretty much the same than just assigning it a whole new blank Dictionray right?

wintry quarry
north kiln
#

One clears the dictionary, the other allocates and assigns a completely new instance

frigid sequoia
wintry quarry
#

I mean accessing the dictionary through those references you will find it has been cleared

north kiln
#

If a dictionary has previously been populated it may have grown, resizing its backing arrays to accommodate the data that was previously assigned.
Clearing that just resets that data, it remains allocated.

#

A new instance is unrelated new data that's only referenced where you newly assign it, and will have to reallocate space as it grows

frigid sequoia
#

So if I am making a new instance I am... liberating space?

north kiln
#

If the previous references to the old dictionary are set to null, sure. But whether it's liberating for a good reason or not is usually the driver to whether you new or clear

wintry quarry
# frigid sequoia What do you mean visible?

I mean:

Dictionary<string, string> a = new();
a["hi"] = "hello";

// b is now another reference to the same Dictionary
Dictionary<string, string> b = a;

a.Clear();
Debug.Log(b.ContainsKey("hi")); // false

a["hi"] = "hello";

// here we reassign a to a new dictionary
a = new();

// b still points to the old one
Debug.Log(b["hi"]); // prints "hello"```
north kiln
#

if it's just gonna regrow then deallocating is a bad idea because garbage collection and allocation is not free

frigid sequoia
wintry quarry
#

it's not a copy

#

they are both references to the same underlying object up until the part where a is reassigned

#

that's why we call them references

#

THere's only one dictionary

#

we are clearing the one dictionary

#

so both references can "see" the changes

frigid sequoia
#

Yeah, but wasn't your reference to a snapshoot of the state of the dictionray at one specific time and therefore not changed?

wintry quarry
#

no.

#

There is no snapshotting

#

both references are equal references to the one existing dictionary

#

That's the difference between a value type and a reference type

#

If it was a value type object, for example a Vector3 or an int, then it would behave as you say

frigid sequoia
#

I have read that like 10 times I do not understand it. Like how can I even tell them apart?

north kiln
frigid sequoia
#

What if a wanted a snapshot of the DIctionary?

north kiln
#

var copy = new Dictionary<ExampleKey, ExampleValue>(otherDictionary);

wintry quarry
#

What vertx wrote just above me does that

#

note that when you want to actually create a new separate object we must use the new keyword

wintry quarry
frigid sequoia
#

Why declare it as var and not as Dictionary?

wintry quarry
#

in this case, both addresses are the same

wintry quarry
#

wait

#

sorry I didn't lol, only vertx did

#

it's less typing is all

bright zodiac
north kiln
#

var copy = new Dictionary<ExampleKey, ExampleValue>(otherDictionary);
Dictionary<ExampleKey, ExampleValue> copy = new Dictionary<ExampleKey, ExampleValue>(otherDictionary);
Dictionary<ExampleKey, ExampleValue> copy = new(otherDictionary);

#

They're all the same, who cares how you write it

bright zodiac
#

see the gif animation about ref vs value type

#

should be easier to digest

void thicket
#

otherDictionary.ToDictionary() UnityChanCoder

north kiln
#

I hate that gif, why coffee, something that makes no sense to have a copy or reference of

void thicket
#

Yeah

#

It doesn't explain actual mechanism

north kiln
#

At least it explains the semantics, but yeah it makes me feel ick šŸ˜„

bright zodiac
#

y'all already explained it, some visuals reps would defo help

#

no need to say the same exact thing... waste of breath šŸ˜‚

frigid sequoia
#

Yeah, I understand the concept, I just don't understand how it works

wintry quarry
#

I think of reeference variables as pieces of paper with addresses written on them. With the object being referred to as the house. itself

#

a = something; changes the address written on a

#

a.Clear() actually clears out the house at the address

#

so if a and b hold the same address, clearing out the house at address a will also clear the house at address b

#

since they're the same house

bright zodiac
frigid sequoia
#

So if I do this b would remain as 1 no matter what I do to a

void thicket
#

I hate to say this but learning C is easiest way to understand

frigid sequoia
#

What if I don't want it to?

wintry quarry
wintry quarry
#

assuming a was 1 when the emthod was called

north kiln
frigid sequoia
#

So... if do like this u mean????

sacred cradle
#

hello, do i still need Time.deltaTime in an IEnumerator? Image is start of IEnumerator function

#

end of function

void thicket
#

!code

eternal falconBOT
wintry quarry
north kiln
sacred cradle
#

well this seems to be not working correctly:

transform.localPosition = transform.localPosition+new Vector3(velocityX * Time.deltaTime, velocityY * Time.deltaTime, velocityZ * Time.deltaTime);
wintry quarry
#

what are you expecting it to do

#

and what's happening instead?

sacred cradle
#

its like its really slow

#

and doesnt move at all

wintry quarry
#

Where is this code?

sacred cradle
#

and normally without Time.deltaTime its moving normally fast

wintry quarry
#

You need to show the full context

sacred cradle
wintry quarry
#

Also wht are the velocity variables set to?

#

I mean show all the code

sacred cradle
wintry quarry
#

not just a single line

frigid sequoia
sacred cradle
#

hold on

#

sorry, smth came up

#

ill be back in like an hour or two

frigid sequoia
#

Like do I have to know which ones do that of aiming at the same memory space rather than snapshooting?

wintry quarry
north kiln
frigid sequoia
#

I read that I am like "what?" on each other word

north kiln
#

Then please ask questions about what you don't understand, pointing to the paragraph in question

frigid sequoia
#

It's not anything in particullar

north kiln
#

as if the resource I've written is not enough I would like to improve it instead of just having endless pointless rehashings of things it already explains

frigid sequoia
#

It's like reading about a subject u don't really understand yet and you are like "wait, what was that again?" you know?

#

Like I dunno, I guess I am used to textbooks where 90% of the words are like actual filler

#

But I just understand something a thousand times better with a single practical example than reading the documentation 100 times

sand snow
#

how do I reference a script from a different script

ivory bobcat
sand snow
ivory bobcat
#

If you're needing a reference during runtime, when you instantiate the object you'd pass a reference to the instantiated object

dense pike
#

Can someone help me. I need a script that plays object animation on play trigger enter

slender nymph
#

!ask

eternal falconBOT
burnt vapor
azure citrus
#

hi i'm messing around a prefab i installed on asset store, and i'm trying to get it moving, but only its outline moves and not the object itself. does anyone know why

#

the script only moves the parent object so far

barren rampart
#

Hi does anyone have an idea what my be wrong with by character? I added a camera to follow it, but there seems to be a flickering in animations. I tried to record it, but it seems fine on the recording. Before I added the camera follow it was fine too.

real thunder
#

if that's the case simply turn it on interpolate, if it's not you should probably share camera movement code

barren rampart
#

I don't really know what that interpolation means

real thunder
#

yep, everyone getting bumped onto this issue

#

interpolation is when the value getting calculated between other values, I guess?
anyway
this specific case it means that gameobject is still moving inbetween physics frames
now it would visually lag one physic frame behind it's actual position, as a drawback, but it's almost always is fine
if it's not fine extrapolate exists but it can create another problem where the object appear further than it actually is within same 1 physic frame error

#

there are 50 physic frames in one second by default
but you can have more than 50 fps in one second
if you happened to get new visual frame without getting new physic frame
physically moving objects like rigidbodies won't move
and that would make an illusion of lag

#

if you pay close attention and have high fps you might be noticing it
it usually only a noticeable issue if a camera following such object

#

interpolation on rigidbody would add fake movement in between physic frames so it always move somewhat smoothly

#

fake in a sense you can't get collisions and stuff on such fake movement frames

zinc shuttle
#

i have a doubt, so i am making a 2D game where you can interact with the building to go in the building, but so many different buildings are there, should i use the load Scene method or anything better i can do here

real thunder
real thunder
#

it's a general gamedesign question

#

is they are small and there is alot of them teleporting seems better, if not scenes

barren rampart
#

thanks for the explenations and for the help

#

have a good one

teal elk
#

How do I make my speed boost properly follow behind my player and not rotate with the player

real thunder
#

so particles no longer exist as player transform childs (kinda)

teal elk
timber tide
#

global space is correct to prevent them rotating after instantiating, but you need local direction upon instantiation to rotate them at the start

inland cobalt
#

How does order of execution work with unity? For example will it wait for an entire Start() function to complete before mvoing onto the next, or do they happen semi in parallel? Same thing with stuff like FixedUpdate(), im getting some inconsistencies with my code and im wondering if that is the cause

grand snow
inland cobalt
cold elbow
#
using UnityEngine;

public class BallController : MonoBehaviour {
    public float speed = 10f;
    private int _scannerLayer;
    private Rigidbody2D _rb;

    private void Awake() {
        InitializeRigidbody2D();    
        InitializeScannerLayer(7);
    }
    private void Start() {
        _rb.linearVelocity = _rb.linearVelocity.normalized * speed; //set linear velocity
    }
    private void OnCollisionEnter2D(Collision2D collision) {
        var normalizedVelocity = _rb.linearVelocity.normalized * speed;
        _rb.linearVelocity = normalizedVelocity;
        
        if (collision.gameObject.layer == _scannerLayer) {
            Debug.Log("Ball detected colliding with scanner. Destroying Ball.");
            
            DestroyBall();
        }
    }
    
    private void DestroyBall() {
        Destroy(gameObject);
    }

    private void InitializeRigidbody2D() {
        _rb = GetComponent<Rigidbody2D>();

        if (_rb == null) {
            Debug.LogError("Ball Rigidbody component is missing on game object.");
        }
    }

    private void InitializeScannerLayer(int layer) {
        _scannerLayer = layer;
    }
    // Update is called once per frame

}

In oncollision2D in the if statement condition it always evaluates to false even tho I had already set up the game object layer properly on the unity inspector, I've tried everything it still doesn't work

keen dew
#
Debug.Log($"{collision.gameObject.name} collided, it has layer {collision.gameObject.layer}, scanner layer is {_scannerLayer}");

Put this outside the if statement and show what it prints

hasty dragon
#

im using the character controller component and theres no gravity

#

what do i do?

wintry quarry
# hasty dragon what do i do?
  1. Decide if you want gravity
  2. If you do, simulate gravity yourself in your code.
  3. Optionally use the SimpleMove function instead of Move, which has built in gravity
#

Almost any tutorial with Characteracontroller will cover how to simulate gravity though

hasty dragon
#

i see

coarse magnet
#

hey everyone, currently i have spawners in my project that spawns an enemy, how do i make it spawn a different enemy after a certain time?(the game is a plane shooter)(i have the timer set on a different script)

wintry quarry
coarse magnet
#

i know the method but idk how to implement it

#

like how do i change the variable inside a script midgame?

#

wait

#

i think i figured it out

wintry quarry
#

With the = operator

coarse magnet
#

yeah that šŸ˜…

fast fern
#

I switched to VS Code since it some auto completes for my code, but it seems like I'm still missing a lot of options
This is what I get:

#

these I don't see

wintry quarry
wintry quarry
#

Then why would they show up?

fast fern
#

wait me lost

#

I think those are the defualt?

wintry quarry
#

No

#

They're not default

#

Those are some custom classes and methods in wherever you took that screenshot from

#

LogicScript is not a default anything

fast fern
#

oh

#

dayum, I'm just super lost then

#

I'll try everthing again, thanks for your time

cold elbow
#

it doesn't detect the collision with the layer I want it to

wintry quarry
fleet venture
#

why cant i assign this object to a field of type Camera

#

should i be using a diff type?

cosmic dagger
fleet venture
#

yes

#

and its a static field

cosmic dagger
#

A prefab cannot reference scene GameObjects . . .

fleet venture
#

so then how do i do it

cosmic dagger
#

Huh? Static fields don't display in the inspector . . .

fleet venture
#

they do

#

it is

real thunder
#

nonononono, they don't

cosmic dagger
real thunder
#

unity don't support serializing of static fields

#

or something like that

fluid remnant
#

static field belongs to the class not the instance thats why

fleet venture
#

oh wait the editor wasnt updating because my code had other errors

#

but then what if i want it static

#

ye i want this shared for all instances of the class

#

i cant do Camera.main because thats expensive apparently

cosmic dagger
fluid remnant
fleet venture
real thunder
#

GameObject.Find worst case

fluid remnant
#

no

fleet venture
#

well i would rather have a best case

#

this is a prefab tho if that matters

fluid remnant
#

use a singleton pattern or Dependency Inject it

fleet venture
#

a singleton makes no sense here

real thunder
#

this case I would use a singleton holding references

fleet venture
#

i mean it doesnt HAVE to be static

real thunder
#

it's not great I agree

fleet venture
#

but it does make my life a lot easier

real thunder
#

make it static, make it non static, assign non static to static on Awake?

fluid remnant
#

without explaining the use case is not really productive to suggest anything

real thunder
#

fair

fleet venture
#

ok i just want a draggable object

cosmic dagger
fleet venture
#

this is what i have so far

#
public class DraggableObject : MonoBehaviour
{
    private bool _dragging = false;
    public static Camera MainCamera;
    
    private void Update()
    {
        if (!_dragging) return;
        var mousePosition = MainCamera?.ScreenToWorldPoint(Input.mousePosition);
        if (mousePosition == null) return;
        transform.position = new Vector3(mousePosition.Value.x, mousePosition.Value.y, 0);
    }
}```
#

i had Camera.main first but thats expensive

fluid remnant
#

all this for a camera?

fleet venture
#

i got a warning

#

ye

#

the main camera

fluid remnant
#

just cache camera in awake with camera.main

fleet venture
#

oh

#

idk what awake is

rocky canyon
#

camera.main isn't that expensive as a matter of fact

fleet venture
#

but ig that works

fluid remnant
#

its the initialization method

fleet venture
rocky canyon
#

it used to be

cosmic dagger
fleet venture
#

Lazy is a cache right?

fluid remnant
#

it used to be much more expensive that it is these days

fleet venture
#

its nullable

#

its not

cosmic dagger
fleet venture
#

its an artifact from what i had first

fluid remnant
#

Unity Objects cannot be null checked his way

fleet venture
#

bruh why not unity has so many weird quirks

fluid remnant
#

they are internally handled

fleet venture
#

so i cant get a NRE?

cosmic dagger
deft breach
#

Just assign the Main Camera in Awake its 1 time call pretty cheap

fleet venture
#

ok

fluid remnant
# fleet venture so i cant get a NRE?

After the underlying component is destroyed, the C# object for the
MonoBehaviour remains in memory until garbage is collected. A MonoBehaviour in this state acts as if it is null. For example, it returns true for a "obj == null" check. However, this class doesn't support the null-conditional operator (?.) and the null-coalescing operator (??).
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/MonoBehaviour.html
The null-conditional operator (?.) and the null-coalescing operator (??) are not supported with Unity Objects because they cannot be overridden to treat detached objects objects the same as null. It is only safe to use those operators in your scripts if there is certainty that the objects being checked are never in a detached state.
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Object.html

deft breach
#

private void Awake() {
MainCamera = Camera.main;
}

fleet venture
#

ye i got it

real thunder
#

wait if obj == null is true how can ?. not be supported; it's the same thing in my head ><

cosmic dagger
real thunder
#

oh

#

it's worse than I thought

rocky canyon
# fleet venture bruh why not unity has so many weird quirks

Game engines are incredibly powerful software, handling a vast number of systems that all need to work together seamlessly. With so many moving parts, there are countless quirks and complexities that make them challenging to fully grasp.

game-engine lyfe

fleet venture
#

btw i cant get the OnMouseDrag to work properly

#

like its really buggy

#

is that like a known thing?

fluid remnant
#

those methods don't work very well

fleet venture
#

ok so i should just create my own thing with OnMouseEnter Exit Down and UP?

fluid remnant
#

event system has better ones or just make your own raycast behaviour

fleet venture
#

what im not about to create a full raycasting system

rocky canyon
#

ive always wrote my own drag and drop mechanics using the pointer interfaces

fleet venture
#

im a beginner in unity T-T

fluid remnant
fleet venture
#

and my teacher said the event system only works with UI components

fluid remnant
cosmic dagger
rocky canyon
#

event system works w/ anything w/ a collider

#

yea ur teacher must not be a very great teacher

fleet venture
#

you mean the EventTrigger component right?

fluid remnant
#

you can add Physics raycaster and it works with colliders

rocky canyon
#

Graphics Raycaster innit?

fluid remnant
#

Physics Raycaster

rocky canyon
#

ahh ok

fluid remnant
#

I believe graphic is for canvas

fleet venture
#

i have no idea what to do

#

so using OnMouseEnter and stuff also wont work?

fluid remnant
fleet venture
#

how do i show it

#

like a video?

fluid remnant
#

what is the intended behaviour vs what is currently happening?

fluid remnant
fleet venture
#

i already changed it away from the OnDrag though

deft breach
fleet venture
#

one second

cosmic dagger
fleet venture
#

eh it works but if i move my mouse too fast it doesnt

#

because then it exits

#

and it stops

fluid remnant
#

are you doing drag and drop? just enable and disable a bool and use update to follow

fleet venture
#

thats what im doing

#

it doesnt work

#

i made a video hold on

fervent abyss
#

is there an event to track text changes in textmeshpro?

fleet venture
fluid remnant
fervent abyss
cosmic dagger
fluid remnant
fleet venture
#

this is the code btw ```c#
public class DraggableObject : MonoBehaviour
{
private bool _dragging;
private bool _mouseDown;
private static Camera _mainCamera;

private void Awake()
{
    _mainCamera = Camera.main;
}

private void Update()
{
    if (!_dragging || !_mouseDown) return;
    var mousePosition = _mainCamera.ScreenToWorldPoint(Input.mousePosition);
    transform.position = new Vector3(mousePosition.x, mousePosition.y, 0);
}

private void OnMouseEnter()
{
    _dragging = true;
}

private void OnMouseExit()
{
    _dragging = false;
}

private void OnMouseDown()
{
    _mouseDown = true;
}

private void OnMouseUp()
{
    _mouseDown = false;
}

}```

fleet venture
#

i create a new sprite from a prefab at teh mouse position

#

on mouse down on the ui element

fluid remnant
fleet venture
#

then i would like to be able to drag it until mouse up

fluid remnant
#

you have to instantiate the new prefab as already set to follow mousePosition

fleet venture
#

ah

fleet venture
#

even tho i have the event for it

fluid remnant
fleet venture
#
public void AddObject(GameObject instance, bool isBackground)
    {
        gameManager.IncreaseObjectLayer();
        var mousePosition = Camera.main?.ScreenToWorldPoint(Input.mousePosition);
        if (mousePosition == null) return;
        instance.transform.position = new Vector3(mousePosition.Value.x, mousePosition.Value.y, 0);
        var prop = instance.GetComponent<Prop>();
        prop.SetDragging();
    }```
#
public void SetDragging()
    {
        _dragging = true;
        _mouseDown = true;
    }```
fluid remnant
fleet venture
#

apparently

fluid remnant
#

why not set it to false in OnMouseUp

fleet venture
#

dragging checks if you rmouse is over the object

#

its meant to stay true when you just rleease the button

#

but it also checks if mousedown is true

#

which shouldnt be true as i set that false in OnMouseUP

rancid tinsel
#

what does this mean?

rocky canyon
#

ur calling the class itself

#

not an instance of it

fluid remnant
#

is Instance actually static?

rocky canyon
#

^ check that

rancid tinsel
#

it is

#

so is currentPoolSize though maybe that's the issue

deft breach
rancid tinsel
#

the idea was to have it not change from outside the class

#

but be readable

fluid remnant
fleet venture
#

i though tit was only when entering

#

then how do i do this

rancid tinsel
cosmic dagger
fleet venture
#

so OnMOuseEnter is called repeatedly?

fluid remnant
fleet venture
#

well either way shouldnt the exit set it to false and then its not true anymore

#

untill you reenter it

rocky canyon
#

if u would debug the values ur using u'd understand alot more of whats happening and just Debug in general

deft breach
#

When your Mouse is over the thing yes

rancid tinsel
#

ok so just to confirm if i understand how this works correctly - get is public, meaning it can be accessed from anywhere, but set is private meaning it cannot be changed from outside the class?

rancid tinsel
fleet venture
#

well idk how im meant to debug this if i need my mouse to test it

rocky canyon
#

tf u talkin about? debugs show in the console window

fluid remnant
#

Debug like everyone else does use Debug.Log

fleet venture
#

oh i always use breakpoints

#

oh btw

fluid remnant
#

or if you want to see them on Screen you can also use GUI.Label in IMGUI

fleet venture
#

ive not figured out how to get the consoel window open without an error message showingup

fluid remnant
fleet venture
#

cuz then i can click on the error to open it

#

but if i have no error idk how to open it

rocky canyon
fluid remnant
#

there is separate tab for it

rocky canyon
#

ur gonna have abad time building an entire game w/o the ability to check the console logs

fleet venture
#

ah

rocky canyon
#

put logs in everything.. every method.. ever function. all that stuff.. then play the game as usual..
then u can watch and pay attention to what logs show and WHEN

#

it'll šŸ’Æ help ur understanding

fleet venture
#

oh

#

ye ive always used breakpoints

#

but thats a bit hard with this

rocky canyon
#

those are great too..

#

but yea simple debugs wuld be better in this situation

#

where ur just trying to observe the flow and whats actually being called

fleet venture
#

ok nah this works how i expect it to work

fluid remnant
#

you can also do onscreen debugging if you feel brave to use IMGUI

    private void OnGUI()
    {
        GUI.Label(new (0,40,100,25), $"bool {mybool}");
    }```
fleet venture
#

it only calls it when it enters it

rocky canyon
#

its nice to know for sure right?

#

🫠

fleet venture
#

true

#

OnMouseUp doesnt get called

#

can that not be called if OnMouseDown isnt called or something?

deft breach
#

Maybe if you just try simplifing it at first:

    {
        gameManager.IncreaseObjectLayer();
        var mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        if (mousePosition == null) return;
        instance.transform.position = new Vector3(mousePosition.Value.x, mousePosition.Value.y, 0);
    }```

Then remove the SetDragging and change the Awake Method:
``` private void Awake()
    {
        _mainCamera = Camera.main;
        _dragging = true;
    }```

And lastly, also remove OnMouseEnter() and OnMouseExit()
Dont know if this works buy you could give it a try @fleet venture
fleet venture
rocky canyon
fleet venture
#

wait nvm

deft breach
#

thats in the update i thought

fleet venture
#

ye it is

grand snow
#

Are you using the input system pointer events or the mouse messages?

rocky canyon
#

but tbh it seems like OnMouseUp would still get called even if it misses the Down

fleet venture
#

so its definetly better

#

but it doesnt fix the mouse up problem

fleet venture
rocky canyon
#

yea i was just guessing.. as i havent ever relaly had code like this

deft breach
#

and you only set dragging to true in MouseDown and Awake right?

rocky canyon
#

theres always a down when theres an up lol

fleet venture
# deft breach and you only set dragging to true in MouseDown and Awake right?

no i also call it here

public void AddObject(GameObject instance, bool isBackground)
    {
        gameManager.IncreaseObjectLayer();
        var mousePosition = Camera.main?.ScreenToWorldPoint(Input.mousePosition);
        if (mousePosition == null) return;
        instance.transform.position = new Vector3(mousePosition.Value.x, mousePosition.Value.y, 0);
        var prop = instance.GetComponent<Prop>();
        prop.SetDragging();
    }```
#

in SetDragging

#

i just set booth bools to true in there

#

i geuss i only need 1 bool now tho

grand snow
fleet venture
#

that sounds quite complicated

fleet venture
#

physics raycaster?

rocky canyon
#

good stuff

grand snow
rocky canyon
#

hella useful interfaces

fleet venture
#

i just implement those and it works?

rich adder
#

just keep in mind with this, UI elements can block your Raycasts

fleet venture
#

oh

rocky canyon
fleet venture
#

i mean

#

i want this object spawned above it anyways

#

wait thats not possible

#

šŸ’€

#

is that possible?

rocky canyon
#

isnt learning fun šŸ™‚

rich adder
#

You can put camera mode to Screenspace camera and set certain plane so sprites can be above

fleet venture
grand snow
#

Its good when you want say a UI button to be usable and not trigger drags for things "behind it"

rocky canyon
swift crag
#

By default, it only provides UI events

#

But it can also provide the same set of events for objects with colliders

fleet venture
#

ohh ye my teacher said that wasnt possible

#

ig he was wrong

swift crag
#

i would have said the same until about uh

#

3 days ago, haha

grand snow
#

Yea, adding the physics raycaster or physics 2d raycaster makes these events work with 3d and 2d colliders