#💻┃code-beginner

1 messages · Page 459 of 1

polar acorn
#

Then things probably aren't being removed from the hierarchy on startup

rich adder
#

whats the current issue?

languid snow
#

like this?

umbral rock
#

yes, because the prefab needs to have it? do i need to put the prefab in the scene and attach the text that way and make it a prefab again maybe?

polar acorn
thick rivet
#

what do the locks on inspector project and hierchy do

languid snow
#

no its alist

polar acorn
rich adder
#

ahh didnt see its a prefab..dammt cutoff inspector..

polar acorn
umbral rock
pulsar forum
languid snow
#

no chat gpt made that sorry

polar acorn
rich adder
pulsar forum
#

There is not, though I don't think that's what he has

terse spindle
# rich adder whats the current issue?

I want "right -> middle -> left"
but it goes "right -> left"

I wanna make it like subway surfers like when you on the right you need twice input to go to left but in this code it takes one input to go to the left from the right

steep rose
polar acorn
umbral rock
thick rivet
polar acorn
pulsar forum
#

Define three x positions and then cycle between them--if you put them in an array you can do left xpos = xPositions[(curInd+1) % 3] and if you go left xpos = xPositions[(curInd + 2) % 3]

polar acorn
rich adder
polar acorn
#

A locked object won't be selected

umbral rock
thick rivet
steep rose
#

The button didnt do that

polar acorn
steep rose
#

Well what exactly did you press

rich adder
#

btw if you're using rigidbody, stick to moving it via rigidbody instead of transform.position
rb.position =
or , rb.velocity . AddForce can work too if you make it velocity mode

polar acorn
thick rivet
terse spindle
#

is there a way I can teleport with rigidbody?

rich adder
#

its not about being "smooth" its about your collisions being accurate

terse spindle
#

its just a capsule

rich adder
#

if you dont want smoothing using .velocity or rb.position

#

its not that hard..

terse spindle
#

oh we can do rb.position?

rich adder
rich adder
#

at least that moves it on the physics loop so its accurate

terse spindle
#

that works for me

#

thanks

languid snow
#

so i did this and now i get this error "Only assignment, call, increment, decrement, wait, and new object expressions can be used as a statement"

steep rose
#

What is the error

#

Oh

#

My bad 😅

eternal needle
pulsar forum
languid snow
#

doing what digiholic said gets me this error

thick rivet
polar acorn
#

yes

polar acorn
thick rivet
languid snow
thick rivet
#

but i still dont what im pressing to make it delete

#

thanks tho the script worked

#

how do i fix the pop ups not poppping up

raw token
rich adder
#

button.onClick.AddListener(() => rolleMeWatever[0].Invoke());

polar acorn
#

Navarone has the right answer then

polar acorn
eternal falconBOT
thick rivet
languid snow
rich adder
thick rivet
polar acorn
rich adder
#

UnityAction 😢

dire tartan
#

i want to make it so you bounce of walls and your momentum is kept is there a way to put it on the player instead of putting a bouncy physics material on every wall?

languid snow
rich adder
dire tartan
#

im making a 2d game and whenever i have the velocity flipped on collision it works unless you go full speed into a wall

languid snow
rich adder
#

I try not to rely on physics material when i can, just using reflect so it bounces nice and accurate without losing force

dire tartan
#

im trying to make a game in the genre of like jump king where its hard and ur constantly moving and i want it that if you hit a wall it just makes you keep going into the other direction

deft grail
dire tartan
frank flare
#

Can someone tell me why Debug.Log("Trying to spawn an item"); isn't being outputted? (the SpawnItem function doesn't seem to work at all)

eternal falconBOT
dire tartan
#

i havent got to it working on certain angles and only on walls yet

#

but im assuming the problem will still be there even if i do

frank flare
deft grail
# dire tartan https://hatebin.com/levhdzqqih

so what is this, normal user input but when they let go of "d" the velocity just keeps going?
and if it hits a wall you want it to flip?

or do you want it to be automatically moving left/right like an NPC

dire tartan
#

i want it so that when the user clicks d or a it adds speed in that direction and they are always sliding

#

and if they hit a wall it should just bounce them the other way keeping their momentum'

deft grail
#

so just store the current velocity and use that

slender nymph
# frank flare https://hastebin.com/share/urewuxewon.csharp

GetKeyUp is only true for the first frame that the key is released. so if the h key is released before that other condition is true then the if statement as a whole will be false until the key is pressed and released again after that other condition is true

#

oh and you don't start the coroutine correctly either

frank flare
slender nymph
#

if only you'd bothered reading the other message before you replied too

#

and also next time, you need to provide that context

frank flare
slender nymph
#

have you looked up how to start a coroutine?

steep rose
frank flare
#

yes, I don't know what I did wrong

slender nymph
#

what did you find in regards to starting a coroutine

steep rose
#

Go to unity docs, they will tell you exactly how

steep rose
deft grail
steep rose
#

He shouldn't be += his velocity then

frank flare
deft grail
frank flare
#

ok thanks it worked

steep rose
#

Ah nvm I read wrong 😅

slender nymph
#

there's nothing after the wait so it just waits for no reason
wait nevermind, it's inside the loop. your nesting of the coroutine inside of the if statement in update makes this a real pain in the ass to read

deft grail
dire tartan
#

when i jump on the floor it works it flips my velocity fine

#

but its when i go into a wall that it just doesnt flip

#

and goes to a weird small number

rich adder
#

show current code

deft grail
#

what would the X velocity be against a wall

#

like nothing

dire tartan
#

thats true

#

i see

deft grail
#

you would need to store it before you hit it i guess or not sure exactly

dire tartan
#

so would i need raycasts?

rich adder
#

just use Vector3 reflect if you want the opposite velocity on wall hit

dire tartan
#

wouldnt that still be the same issue tho?

#

if i do it on hit then on hit its gonna lose all its velocity

#

unless im misunderstanding how it works

steep rose
#

If you flip the velocity as soon as you hit the wall or if you get close to the wall it shouldn't stop velocity

#

UNLESS the object is already stopped

rich adder
dire tartan
#

yeah and to record it would that mean i need to use raycasts to check before its gonna collide?

steep rose
#

You can use raycast or triggers, etc. whatever floats your boat

rich adder
tender hamlet
#

So im working on this project and i need to be able to get the x, y, z position of a gameobject once i click on it, and im able to use that data in a script as real time data. so it updates as the object moves. is there any website i can learn something like this? or any example codes, something that i can teach myself

dire flare
#

Pls someone should help me with this for 1 week now try to solve where the problem comes from

eternal falconBOT
dire flare
#

How to shoot

rich adder
#

also is that really monodevelop..

polar acorn
# tender hamlet So im working on this project and i need to be able to get the x, y, z position ...

The hard part of this is detecting when you click on an object. There's actually several ways to do this. Depending on how your project is set up, whether the object has a collider, whether this script is on the object vs on some manager object, etc., but this goes over a few of them:
https://learn.unity.com/tutorial/onmousedown

Once you know which object you clicked on, it's as simple as getting that object's .transform.position to get the XYZ

Unity Learn

How to detect mouse clicks on a Collider or GUI element. This tutorial is included in the Beginner Scripting project. Previous: GetAxis Next: GetComponent

polar acorn
rich adder
#

I shall steal this image for future use 😈

tender hamlet
polar acorn
tender hamlet
# polar acorn Ah, good. Then it's just `.transform.position`. Whatever component you have acce...

i dont exactly get it, this isnt with a specific item. For more of an explination i have a script that generates a "rope" around two circles and i use the splines addon to do that. I use a bunch of math to find where the points the rope needs to be placed. The user is suppose to place two circles, and then click on both circles and it will generate the rope around the two circles. I need the position of both circles to calculate the math, so i need to be able to use it as a variable. and these game objects dont have a defined name so how will i be able to import it into the script?

slender nymph
steep rose
dire flare
#

Here right

steep rose
#

Yes

#

These are the !code guidelines

eternal falconBOT
dire flare
#

Where is the code guide line

slender nymph
dire flare
#

Alright thanks bro

zealous geode
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player_Inventory : MonoBehaviour
{
    public List<Item> Items;
    public int InventoryIndex;
    public static Player_Inventory instance;
    // Start is called before the first frame update
    void Awake()
    {
        if(instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(instance);
        }
    }

    public void PickupItem(Item item)
    {
        Items.Add(item);
        Destroy(item);
    }

    public void DropItem(Item ItemToRemove)
    {
        if(Items.Exists(i => i.Equals(ItemToRemove)))
        {
            Items[InventoryIndex] = null;
        }
    }
}
    public void Interact()
    {
        RaycastHit hit;

        if (Physics.Raycast(_camera.position, _camera.forward, out hit, interactRange))
        {
            GameObject target = hit.collider.gameObject;

            if (Input.GetKeyDown(KeyCode.E) && target != null)
            {
                if (target.CompareTag("Item"))
                {
                    Debug.Log(target);
                    Player_Inventory.instance.PickupItem(target.GetComponent<Item>());
                }
            }
        }
    }

Hello, I'm having an issue i've struggling with and I can't think of a solution. The thing is that I want to be able to pickup and drop items that are stored in the player inventory. My problem comes when I pickup an item from world space and try to store it in the inventory: my Destroy(item) line also destroys the reference to that gameObject and it's data. I thought about using an Instantiate to clone it and add it but I don't know if that would be effective since what I want to do is to make them dissappear from world space until dropped.

slender nymph
#

you could just set its gameobject as inactive

rocky canyon
#

hide it

zealous geode
#

I thought of that too, but in terms of performance, is that ok to do so?

rocky canyon
#

better to do

slender nymph
#

well if the player were to pick up and drop the item multiple times then simply disabling the object would be more performant. however if the player were to pick up the object and then never drop it again, then technically just storing the item data to later instantiate it would be more performant. so really itdepends

rocky canyon
#

instead of spawning a new projectile everytime ur weapon shoots.. the more performant way is to use a pooling system

#

that recylces the gameobjects.. just enabling and disabling them.. (more performant than spawning/instantiating)

zealous geode
#

I see, I'll go with that solution then

#

Thank you so much

honest trench
marble hemlock
#

how would i go about setting up an on screen button to be clicked, and when its clicked it runs Application.Quit();

honest trench
#

use on click

summer stump
#

Or subscribe the button directly via code instead of using the inspector, if you know how

marble hemlock
#

thanks UnityChanThumbsUp

slender nymph
reef bluff
#

im trying to run unity in sandobxie plus

#

idk if you call it a virtual machine but ye

#

but in unity hub it says I dont have any licenses

#

even though I am signed into my account

marble hemlock
#

ngl im struggling

#

is

public class CloseGame : MonoBehaviour
{
    public void Quit()
    {
        Application.Quit();
        Debug.Log("QUIT");
    }
}

not enough for it to reference it on the button?

reef bluff
#

where is that info usually stored? I may need to add the file or folder to the sandbox

deft grail
deft grail
#

then just need to hook it up to the event in the inspector on the button

marble hemlock
#

im not getting an option to reference the method ;-;

deft grail
#

instead of the script itself

marble hemlock
#

OH

#

ahhh
thank you

reef bluff
marble hemlock
#

adding debug.log is really useful

reef bluff
#

im assuming there is a folder or .exe I am missing but im not sure

marble hemlock
#

i was trying to figure out why my menu was spazzing out but i added a message to it and it was freezing the game every frame 💀

reef bluff
#

i gave it access to both the unity program folder and unity hub folder so it has everything in them

meager gust
reef bluff
#

i dont have a second computer lol

deft grail
#

and test it like that

#

or there is solutions to run multiple on 1 pc im pretty sure

reef bluff
marble hemlock
#

yanking it out of update should fix it

reef bluff
#

cuz i used to use parrelsync

#

before integrating steam

deft grail
marble hemlock
#

putting things in update has unexpectedly been a large cause of my bugs because i just kinda instinctively do it

#

okay well now its just not working kekwait

honest trench
#

i was just bout to go to bed but are u available to help now lmao

deft grail
#

and check if it hits something

honest trench
#

i was doing that but it wasnt very accurate for some reason

#

like on some objects it worked

#

on others it just wouldnt hit

reef bluff
#

i ran this exe i found that had to do with licensing

#

i got this im wondering if it explains anything lol

marble hemlock
#

okay this is the last thing im going to work on

deft grail
deft grail
marble hemlock
#

i originally put in void update, and then that caused it to run every frame, which resulted in my mouse glitching in and out, and usually getting sent back to the center

honest trench
#

nah i can just get this old code back gimmie like 5

marble hemlock
#

now its just not running and im actually not sure how i fix that

honest trench
#

i remember it pretty much

deft grail
#

ah ok, you should be checking Input in Update

#

and then in the if statement of the key press, changing the state

#

because rn it would just do it constantly if these methods are in Update?

marble hemlock
#
    private void Update()
    {
        Inventory();
        Menu();
    }

was what i had

#

i wanted it so the player could click esc, or u, to their corresponding UI, and then it would disable movement and camera movement, but allow them to move their mouse around

deft grail
#

line 33 to 41 should also be in the if statement of the Input, not sure why it isnt

deft grail
#

and then just move lines 33 to 41 inside of the If statement for the key press

marble hemlock
#

like this?

deft grail
marble hemlock
#

well originally i just had them separate because i wanted it to make sure it

#

hold on give me a second i probably had a thought

#

i think the intention was to make sure that first line ran first but now that im looking at it now, i think it runs it first anyways

#

i seem to have broken something unrelated

deft grail
#

what did you change

honest trench
marble hemlock
#

well i tried to move it up but now menu isnt being acknowledged
gonna see if i can fix it

deft grail
honest trench
#

wait hold up u right

#

yeah that was the problem, why would that have an effect tho? every anomaly had both the tag and layer because I was orignally gonna do tags but I switched to layers and just forgot to change the code, so why wasnt it working anyways

#

thanks for the help tho

marble hemlock
#

ig adding private in front of it just puts it back together what is this notlikethis

deft grail
honest trench
#

yee

deft grail
deft grail
marble hemlock
#

im incredible i broke another thing
i mean i got the glitchiness gone but

#

its kinda fun

marble hemlock
honest trench
#

its weird how certain parts of the building work and other parts dont

#

where you click on it determines if it works or not when it should just be whenever u click on it no matter where

deft grail
honest trench
#

wait hold up i think ur right

#

let me fix this

#

okay i think its good now but if i see any more problems ill let you know

deft grail
honest trench
#

ah alright

#

all good

#

thanks so much :)

deft grail
honest trench
#

yea i never notice the small things

#

which makes coding a weird hobby to be into but ah well

lean anvil
#

im confused on what this means and how to fix it

ivory bobcat
#

Change the name of the class

lean anvil
marble hemlock
#

why is brackeys bad

polar acorn
#

Basically: his beginner stuff isn't good because he doesn't actually teach_code_ well. He teaches systems, and the code is often purely demonstrative and you should not be copying it directly

frozen gorge
#

yeah even as a beginner I noticed some sloppiness in his content

polar acorn
#

Brackeys is probably more of an intermediate level tutorial series, his videos going into a specific system like navigation or post processing, etc., are great broad overviews. But like most people who are good at something they don't really know how to explain the early stuff they've long since encoded into muscle memory

mint remnant
#

three is a spot where he is good, and that's if you already know how to code well and are looking at learning what Unity is capable of. He does a wide range of things for that

marble hemlock
#

ahhh. i didnt finish his first person movement video because it felt like i wasnt really understanding most of what he was doing.

#

so i kinda just kept looking for different videos

#

unfortunately my flaw was not immediately going to learn.unity and all their resources

#

its been far more helpful than the tutorials i tried to follow tbh

polar acorn
#

GMTK's intro tutorial is actually not bad. Not the best but it's hard to find someone who is good at coding and good at teaching and good at producing videos.

mint remnant
#

I followed thru with his tower defense tutorial start to finish and I felt like it covered a lot and I learned alot along the way

polar acorn
#

You'll probably just need to try a bunch and figure out your own path

mint remnant
#

One I am particularly fond of is Sebastion LAgue, he covers some more complex systems and is very calm talking about them at a laymen's level

steel stirrup
#

Brackeys is really nice for quickly getting up to speed with an aspect of Unity you haven’t engaged with much, but it definitely expects you to be able to understand why he codes something, which takes experience

sullen perch
#

Can somewone tell me why my terrain aint showing up?

#

Can somewone tell me why my terrain aint showing up?

teal viper
sullen perch
#

mb

cedar bone
#

Anyone have any clue how to get the normal of the collision of a OnTriggerEnter()?

wintry quarry
#

Because there isn't one

cedar bone
#

cause OnTrigger doesnt work for kinematics

wintry quarry
#

OnTriggerEnter works fine for kinematic objects

willow scroll
wintry quarry
#

You could do a Raycast of some kind from the object's previous position and its current position

#

And take the normal from that

#

It really depends what you're actually trying to accomplish

wintry quarry
#

Because there isn't an actual hit point, the objects intersect

cedar bone
cedar bone
wintry quarry
#

So this is a projectile?

cedar bone
#

and i want it to be rotated

#

to the surface

cedar bone
wintry quarry
#

So a bullet hole

#

Do a Raycast from previous position to current position each FixedUpdate

wintry quarry
#

And you can get rid of the OnTriggerEnter entirely then and just use the Raycast for hit detection

opal zealot
#

Was testing out the new Raycast interaction script and hit an Object Reference not set to an instance of an obj. error. I googled the error and its said to be if the Main Camera in question is not tagged properly.

#

I went to check the camera, but it is indeed tagged properly.

#

Did I miss something out while I was checking camera tags?

languid spire
#

show the line of code in question

opal zealot
#

mousePos = cam.ScreenToWorldPoint(mousePos);

languid spire
#

then cam is not set. It is null

opal zealot
#

Ah

#

Lemme fix now.

#

Like this?

languid spire
#

no. cam is a variable in your script

opal zealot
#

Oh

#

Ok

blissful sorrel
#

Sup. Should i combine two if's? If so then how?

languid spire
#

yes.

if (condition) {
// Code
}
#

it's called Scope

blissful sorrel
#

Oh man, and i was curious why this IF was not taking two lines of code like the previous IF... Thanks 👌

opal zealot
#

It'll do.

#

Ok, finally refurbished the PlayerMouseClickInteract code and now I'll need to connect it to the InteractableNPC code: https://hastebin.com/share/icusijicoc.csharp

rare basin
#
private void OnValidate()
{
    if (!gameObject.name.StartsWith("[ENEMY]"))
    {
        gameObject.name = "[ENEMY] " + gameObject.name;      
        EditorApplication.delayCall += RenamePrefabAsset;
    }
}

private void RenamePrefabAsset()
{
    var prefab = PrefabUtility.GetCorrespondingObjectFromSource(gameObject);
    if (prefab != null)
    {
        string prefabPath = AssetDatabase.GetAssetPath(prefab);
        
        if (!prefab.name.StartsWith("[ENEMY]"))
        {
            AssetDatabase.RenameAsset(prefabPath, "[ENEMY] " + prefab.name);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    }
}

im trying to add [ENEMY] prefix to the prefabs, but it doesnt change the prefab names at all, only the objects on the scene do have the prefix added, what am I doing wrong?

languid spire
rare basin
#

i see

#

i should change prefab.name then?

#

should i also keep the RenameAsset?

#

should I also call EditorUtility.SetDirty()? so mayn questions lol @languid spire

ruby python
#

Mornin' all.

sooooo, I have this little bit of code and I'm having a bit of a brain fart with it.

            if (newRecipeItemRequiredNumber < newRecipeItemAvailableAmount)
            {
                newRecipeItemName.color = cannotBuildColour;
                newRecipeItemCost.color = cannotBuildColour;
                newRecipeItemAvailable.color = cannotBuildColour;
                canBuild = true;
                // Turn component text a different colour to show there's not enough available to build the module
            }
            else
            {
                newRecipeItemName.color = canBuildColour;
                newRecipeItemCost.color = canBuildColour;
                newRecipeItemAvailable.color = canBuildColour;
                canBuild = false;
            }

            if(canBuild == true)
            {
                newItemButton.interactable = true;
            }

I know it's not doing what I want, and I know why. Essentially I'm spawning a bunch of prefabs with 'construction component' details and comparing the require value of said construction component to a master list of available components. The buttons start off as non-interactable (non-clickable), what I'd like is for the buttons to be interactable only if all of the require Components are available, I figured a simple bool would be the solution, but I'm having brain issues figuring out how to do it. Anyone have any ideas? 😕 ((Apologies if the codeblock is too long))

prime cobalt
#

Does anyone know why this script to make the player swing around a point wouldn't be working? I included a screenshot of the debug log that I inserted and as you'll be able to see it doesn't make any sense... The player does reach the correct starting position but never moves past that.
https://hastebin.com/share/majeyamewa.csharp

rare basin
languid spire
#

yes, because you forgot the SetDirty

rare basin
#

right

#

well, added it

#

but it still doestn change the prefab name in project files

rare basin
# languid spire yes, because you forgot the SetDirty
private void OnValidate()
{
    if (!gameObject.name.StartsWith("[ENEMY]"))
    {
        gameObject.name = "[ENEMY] " + gameObject.name;      
    }
    EditorApplication.delayCall += RenamePrefabAsset;
}

private void RenamePrefabAsset()
{
    var prefab = PrefabUtility.GetCorrespondingObjectFromSource(gameObject);
    if (prefab != null)
    {
        string prefabPath = AssetDatabase.GetAssetPath(prefab);
        
        if (!prefab.name.StartsWith("[ENEMY]"))
        {
            prefab.name = "[ENEMY] " + prefab.name;
            EditorUtility.SetDirty(prefab);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    }
}
#

it changes in the inspector when i have the prefab selected

#

but not here

languid spire
#

if you want it reflected in Project and Hierarchy then you need to do both

rare basin
#

thats not hierarchy

#

that's from project files

rare basin
#

for hierarchy it already changes in OnValidate

languid spire
rare basin
#

but i want to change the name in the project assets

#

so i can use the project browser and type [ENEMY]

languid spire
#

So add your RenameAsst back

rare basin
languid spire
#

I did not say 'instead' I simply pointed out what you were actually doing

rare basin
#
private void RenamePrefabAsset()
{
    var prefab = PrefabUtility.GetCorrespondingObjectFromSource(gameObject);
    if (prefab != null)
    {
        string prefabPath = AssetDatabase.GetAssetPath(prefab);
        
        if (!prefab.name.StartsWith("[ENEMY]"))
        {
            var newName = "[ENEMY] " + prefab.name;
            prefab.name = newName;
            AssetDatabase.RenameAsset(prefabPath, newName);
            EditorUtility.SetDirty(prefab);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    }
}
languid spire
#

If you don't understand what you are doing, why are you doing it?

rare basin
#

huh

#

if you are not willing to help, stop wasting my and your time, thats the server for to "ask questions"

#

im trying to understand but you are just rude

ruby python
rare basin
#

ok

#

i just asked one question, how to add [ENEMY] prefix to prefab file name, instead he giving me riddles and stuff that doesnt work without explaining, what is this serevr for then if you cannot ask questions, instead all the answers you got is "you dont know what yuo are doing, then why are you doing it"

ruby python
languid spire
rare basin
rare basin
#

adding RenameAsset didin't do it

languid spire
#

And you got the correct answer

ruby python
rare basin
#

Yes, I've read the docs. Thats why I did RenameAsset at first

#

it didin't work so I asked here

#

what's your problem

#

anyway, managed to get it to work, thanks

#

it was just about using GetPrefabAssetPathOfNearestInstanceRoot instead of GetCorrespondingObjectFromSource

lost basin
#

Evening, I have an issue with randomizing my map.


void Awake()
    {
        falloffMap = FalloffGenerator.GenerateFalloffMap(mapChunkSize);

        System.Random random = new System.Random();
        int seed = random.Next(-2147483647, 2147483647);
        Debug.Log(seed);
    }


    void Start()
    {
        GenerateMapAtGameStart();
    }

Everything else is working fine, and my seed is changing (in the console), but the map stays the same

wintry quarry
#

Or rather, that seed variable you're using isn't used elsewhere in the code anywhere

#

It's just a local variable

lost basin
#

O gorreltjies

lost basin
#

I see my mistake

#

Dankie

blissful sorrel
#

How to call a method of a script from another script using "OnCollisionEnter2D(Collision2D collision)"? Unity keeps getting angry because "TakeDamage" is not there.

short hazel
#

!vs

eternal falconBOT
#
Visual Studio guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

barren vapor
stone pilot
#

I just had a quick question, is there a way that I can make a trail renderer a solid color ?

steel smelt
stone pilot
short hazel
#

Modify the gradient so it only has 1 key, of the color you want

#

Or two keys both of the same color

stone pilot
short hazel
#

Changing a gradient from the code isn't complicated, and if you need to do it from the Editor, you can select multiple objects in the Hierarchy and you should be able to bulk-edit the gradient once

steel smelt
#

I think he means he tinted his sprites and wants his trails to be the respective sprite tinted colors

#

so yeah, set it via code

stone pilot
steel smelt
stone pilot
short hazel
stone pilot
#

Nevermind

short hazel
#

Yep there's a communication / translation issue here, my remark wasn't about being in the wrong channel

stone pilot
#

I'll just close for now

#

Thanks btw

blissful sorrel
barren vapor
#

same way how you'd make a variable public

short hazel
#

When you don't specify an access modifier, private is the default. So void Sample() { } is identical to private void Sample() { }

#

-# Only valid for class members. For types (classes, structs, etc.) themselves, internal is the default

blissful sorrel
barren vapor
#

not collision

languid spire
#

why would gameObject have a TakeDamage method ?

barren vapor
#

You had it correct on the previous screenshot. You basicly removed it for some reason

#

oh no. gameObject doesn't have TakeDamage indeed

#

you're trying to access a method in a gameobject (which is the object itself). The method isn't directly in the gameObject, but in a script

strong wren
#

how do i freeze the rotations of a rigid body?

#

rb.constraints = RigidbodyConstraints.FreezePosition; i tried doing this but with freezerotaiton instead but it doesnt work

#

rb.freezeRotation = true; then this

#

at this point i have no idea what to do

blissful sorrel
languid spire
strong wren
#

rb.constraints = RigidbodyConstraints.FreezePosition; this works
rb.constraints = RigidbodyConstraints.FreezeRotation; this doesnt

strong wren
#

and i only found these 2 that are simple

#

i need a simple code and i need to freeze the contrains of the rigid body

#

wait why does
rb.constraints = RigidbodyConstraints.FreezeRotation; freeze the position?

barren vapor
#

For OnTriggerEnter2D is it:

collision.gameObject.GetComponent<script-name>().TakeDamage(DMG);
steel smelt
#

@strong wren So rb.freezeRotation freezes rotation on all axes as intended. Are you manually rotating the object outside of the physics API?

strong wren
#

but when it collides with other gameobjects it moves

steel smelt
strong wren
steel smelt
#

@strong wren You could freeze the position as well, but you can flag rbs as kinematic and they won't be affected by the sim

strong wren
short hazel
#

The docs example show how they combine multiple constraints

strong wren
#

ok i found a way i did this
rb.constraints = RigidbodyConstraints.FreezeAll;

short hazel
#

This is an alternative to using = RigidbodyConstraints.FreezePosition | RigidbodyConstraints.FreezeRotation;
That's how you combine flags enum values, with | (bitwise OR)

blissful sorrel
barren vapor
lost basin
#

it's supposed to be on my mesh

#

Nvm I found why

terse spindle
#

may I ask how to delay in unity

#

I googled it but looks so complicated

polar acorn
terse spindle
#

thanks

#
IEnumerator BeklemekBiraz(){
        yield return new WaitForSeconds(.2f);
    }

(void Update)
        if(Input.GetKey("d")){
            if(canChangeRoad == true){
            canChangeRoad = false;
            if (xvalue < goingSide){
            xvalue = xvalue + goingSide;
            Debug.Log(xvalue);
            }

                StartCoroutine(BeklemekBiraz());
                canChangeRoad = true;
            }
        }
#

can I use it like this

#

should it work

#

dont look very working to me

polar acorn
#

I'm going to assume that the (void Update) is like, psuedo code because that is in no way valid C#

#

But right now your coroutine does nothing whatsoever

#

You start it, it waits, then ends.

#

Nothing happens after the wait

terse spindle
#

wanted to make key delay

polar acorn
#

If you want to delay something happening, you should actually have that something after the wait

terse spindle
polar acorn
#

Starting a coroutine does not pause the function it's in. It runs alongside the code

#

that's what makes it "Co"

#

Your coroutine does nothing

#

There's no code in it

terse spindle
#

yeah

polar acorn
#

Doing nothing, waiting 0.2 seconds, then doing nothing is the same as just... doing nothing

terse spindle
#

after I press d, I change x value and I change the bool to false so it cant work and after waiting .2 seconds bool again turns into true so I can change the x again

#

how do I do that I ask

#

I assume its not going to work with coroutines

polar acorn
terse spindle
#

bool is in the void update so I cant referr to it should I make it public?

polar acorn
terse spindle
#

so I make it public

polar acorn
#

You make it a field

terse spindle
#

field?

polar acorn
#

it doesn't have to be public

#

it just needs to not be in a function

terse spindle
#

why you writing in the 𝓯𝓻𝓮𝓪𝓴𝔂 font

#

okay let me try

polar acorn
#

Italics?

#

A common feature of markdown that has existed for as long as typography?

terse spindle
#

its just a meme sorry

#

thank you bro

#

appreciate it

vital gale
#

Hi, is there a way to find out the origin of a log when using Debug.Log("message....", gameObject) ?

cosmic dagger
verbal dome
winter tinsel
#

how can i find a gameobject within a gameobject that has no children?

verbal dome
#

Yeah if by 'origin of the log' you mean the object, then single click

verbal dome
cosmic dagger
#

also, double-clicking on the log from the console will go to the script where the log was called . . .

winter tinsel
#

how to find a gameobject, within a gameobject

#

and then additonally find if that second gameobject has children

verbal dome
cosmic dagger
winter tinsel
#

okay then uh how do i find a child that has no children?

vital gale
#

yeah I know about the double clicking but I wanted to do a LoggingComponent where it would be given to multiple objects with logging features, and I wanted to quickly differentiate where the log is coming from (To somehow add it to the log message), without me having to manually add it into every log message

cosmic dagger
winter tinsel
#

how do i go down this, checking each gameobject trying to find the first one that has 0 children?

#

(theres more than 6 btw)

verbal dome
#

I use a helper function that takes a string and a color and outputs a colored text

cosmic dagger
# winter tinsel

not a problem. loop through the children of the parent GameObject. you'll find tons of ways how on google . . .

jolly temple
vital gale
verbal dome
#

You would need to click like the second newest link in the stack trace to open that code in the IDE

#

Or do you want to highlight the object itself?

cosmic dagger
verbal dome
#

You should be able to just single click the log

verbal dome
vital gale
# verbal dome So you want to know what code called this Log?

something like the object / script its originating from

E.g. I have this line in MainMenuScript
_logger.Log("Switching to Main Menu.", this);
and I wanted the log to look like ->
Debug.Log($"<color={HexColor()}>{_prefix}: {message}</color>.", sender);
Which would ultimately do something like
"MenuLogger: MainMenuScript: "Switching to Main Menu.""

split dragon
#

Hi. I decided to rewrite the text localization script myself when it changes. Example: We have the source text: "I love you:", and I add 100% to it, that is, it turns out: "I love you: 100%". By changing the language to another one: "100%" will be lost. That's why I needed this script. But there is something written in the script that then completely erases the text if you turn off the enable instance. I tried to comment on void OnDisable (because the text was disappearing because of it), but then nothing worked at all. I'm dumb. Please help me

winter tinsel
#

would this work??

winter tinsel
cosmic dagger
verbal dome
#

It looks like it does what you are asking - except for the "`MenuLogger: " prefix

vital gale
cosmic dagger
verbal dome
#

Which prints as nothing

winter tinsel
#

guess were experimenting

vital gale
verbal dome
#

@vital gale Can also try object.name but I think UnityEngine.Object.ToString() always gives the name anyway

cosmic dagger
winter tinsel
#

cuz i looked at some forums and i dont see something this simple

verbal dome
#

@vital gale Oh I just realized you aren't inputting the object's name anywhere so use sender.name for that

winter tinsel
cosmic dagger
verbal dome
#
Debug.Log($"<color={HexColor()}>{_prefix}: {sender.name}: {message}</color>.", sender);
vital gale
winter tinsel
verbal dome
cosmic dagger
cosmic dagger
vital gale
winter tinsel
cosmic dagger
vital gale
winter tinsel
#

amazing

cosmic dagger
winter tinsel
#

doesnt instantiate

#

why

#

ill drop more code if need be

slender nymph
#

you will need to. and for the love of god don't share screenshots of single lines of code

winter tinsel
#

wtf?

#

wait now it is??

slender nymph
#

had you not actually saved the code before?

winter tinsel
#

nono wait i found the issue

#

on its own it works right

polar acorn
winter tinsel
#

if i uncomment this then it stops working and doesnt even instantiate it

winter tinsel
#

its not in the hierarchy

#

meanwhile when i comment the code i outlined it does instantiate it?

polar acorn
#

If that line runs, it does spawn an object

#

Try logging

slender nymph
#

show the actual context for this code, because on its own there's nothing wrong with it

winter tinsel
#

allright here

slender nymph
#

!code

eternal falconBOT
winter tinsel
#

here

#

heres this too

polar acorn
winter tinsel
#

the point is to make the object a child tho

slender nymph
#

now put some logs in there, remove the entire Start method because it is completely redundant, and make sure that the inventory gameobject and its children are not being destroyed

winter tinsel
#

so what

polar acorn
#

if you comment out the line that sets the parent, chances are your own if conditions are no longer satisfied

#

so the code does exactly what you tell it to do

winter tinsel
#

how does that work if its not a condition in the if??

winter tinsel
slender nymph
#

if you don't set it as a child, then the children likely don't have children so their childcount remains at 0

#

which means your condition is true

winter tinsel
#

so it should instantiate it then right??

slender nymph
slender nymph
winter tinsel
#

so when i do set it as a child it becomes false and it doesnt instantiate it right?

slender nymph
#

can you just fucking put some logs in your code instead of making assumptions

winter tinsel
#

im not making assumptions im asking so i can wrap my head around this

polar acorn
#

You can literally just run the code and have it print what its doing

#

you don't need us to interpret it

slender nymph
#

put this in the loop before the if statement
Debug.Log($"{name} is trying to Instantiate {prefab} on {inventory}'s child: {child} with {child.childCount} children. Possible: {child.childCount == 0}", child);

#

any time you see that "Possible: true" it will have instantiated the object

#

and you can click the log to highlight the object it was set as a child of

winter tinsel
#

possible is false

#

heres the whole thing

slender nymph
vast vessel
#

hey guys!
is there a reason that when i create these "node" objects, that all derive from the class Node, they work fine and have the right type, but after i make a change to a script and re-open unity, their type, turns into the type of the base class?
you can see the types in the console, before and after reloading a script.

here is the code for creating, and storing the nodes in a list of type Node:
https://hastebin.skyra.pw/tuhiqezodo.csharp

winter tinsel
polar acorn
slender nymph
#

oh you know what, it's transform.childCount not child.childCount

winter tinsel
#

oh

slender nymph
polar acorn
#

As I said, if that line runs, then an object is instantiated

slender nymph
#

literally what condition is it checking?

winter tinsel
#

i found another issue hold on

#

ok i fixed that issue now everything works....kinda

#

it instantiates it right in the right child

#

in the right place

slender nymph
#

well that sounds like it is working

vast vessel
winter tinsel
#

it acts like its there, which it is, but it doesnt show up

vast vessel
winter tinsel
#

i cant click it even though its a raycast target and its missing in the ui

slender nymph
polar acorn
#

Or at least custom nodes for one

winter tinsel
vast vessel
#

like, it dosnt make any sense

#

why would their type randomly change

sharp jay
#

polymorphism kekwait

vast vessel
slender nymph
#

if only there were a channel dedicated to the code related to custom editors and the like

vast vessel
#

dude

polar acorn
vast vessel
#

i know that

#

gimme a sec

polar acorn
#

I really don't have enough context behind these nodes, I've literally never touched any custom graph editor code

#

No idea where it's getting its "type" info from

vast vessel
#

the nodes are a custom class

#

here is what happens:
-i create an object of type Start_Node which derives directly from Node.
-i add it to the list List<Node> nodes
-i log the type of the node to the console like this:
Debug.Log(node.name + " - t: " + node.GetType().Name);
Resault:Start Node - t: Start_Node

-i make a change to some random script and save it.
-i return to unity.
-i log the same thing.
Resault:Start Node - t: Node

winter tinsel
# slender nymph you're gonna need to be more descriptive than this

so im very obviously making an inventory, currently im trying to make it so that i can pick up an item, delete it in the space 3d and "add it"(instantiate it), to my "inventory",

now all i did was instead of setting it so the whole inventory i set it to the part where the actual inventory is, because i have it broken up into parts, the main inventory, the gear area place whatever, item description etc

now it works, i press the button to "pickup" the item, it deletes it in the 3d world and instantiates it, then places it in the correct, first child, that has 0 children

issue is it doesnt show up, its an empty "inventory slot",even tho there is very much an item there, i cannot move it, click on it or interact with it, but if i try to manually drag a prefab and instantiate it on a different inventory slot, then try to drag it where the item is supposed to be, it wont let me drop it on that slot, so there is 100% something there and acts as if there is something(which there is)

but the issue is i cant interact with it, the image is missing and even though its a raycast target i cant click on it or move it, in the scene editor it is very much in the correct spot that its supposed to be, its active but still missing,

if i try to manually drag and drop the same prefab from the prefab folder onto any of the "empty"(has 0 children) "inventory slots" it works, but if the code does it it wont work right

sharp jay
slender nymph
sharp jay
#

are these files in their own asemdef?

winter tinsel
vast vessel
# sharp jay is this actually causing issues?

yes.
any data that was saved to a field that specificly existed in say, a DebugLog_Node, will be lost after it turned into Node.
DebugLog_Node's have a message field, which the class Node does not. so i lose the message

#

also when displaying each node in the editor it needs to know what kind of node it is.
see the differance in these two photos? that because all of them turned into a generic Node after reloading a script

sharp jay
#

wait as in the script attached to an object literally changes it's type?

#

I haven't used Unity in close to two years... but I dont see how this is possible

vast vessel
#

so they are not directly attached to a gameobject

slender nymph
#

i'd guess however they are serializing this for the editor window they are using does not support polymorphism or they are just doing something wrong in that regard. of course they refuse to ask in the #↕️┃editor-extensions channel where the question would be more appropriate so i guess they'll never know

sharp jay
#

are you treating a class like a SO? 🤔

vast vessel
#

these Nodes need refrances to game objects in the scene

#

i cant do that with SOs

sharp jay
#

Ah right

vast vessel
#

somebody booted up on the wrong side of the bios this morning

sharp jay
#

I'd assume editor windows get dirtied on a recompile

#

Might be the root cause

#

but I don't know enough to help further

winter tinsel
# slender nymph provide screenshots of what you are seeing

picture one, walking up to the item, picture 2 i press the use button and it deletes the item and instantiates it in the right place, picture 3 i drag and drop the same prefab on a different slot, and it spawns correctly,fourth picture, i drag the manually added prefab to a different slot, but if i try to drag it on the very first block, where the item instantiated by the code is, it wont let me drop it on that space, but i cant move or interact with the item that is there

vast vessel
slender nymph
vast vessel
#

lmao

sharp jay
#

It's good to see beginner code hasnt changed

vast vessel
#

can you tell me why the editor even matters here?
im saving some objects to a list and their type changes

#

lists are a basic part of c#.
the editor just displays them

#

so i think something is wrong with my code

winter tinsel
slender nymph
vast vessel
# sharp jay Ah right

i did try to save these nodes as SOs and it did fix this issue, but then again, no scene object refrances :/

winter tinsel
#

and it doesnt have a sprite the only thing thats changed is the colour (for now)

slender nymph
#

show the inspector for the one that isn't working compared to the one that is

vast vessel
winter tinsel
sharp jay
#

boxfriend will take the blame

winter tinsel
#

first pic (working) second pic(broken)

#

i need to set parent after drag maybe?

summer stump
slender nymph
#

probably related to whatever is in Itemscript then, so most likely you do need to assign that field

sharp jay
#

if you're using IPointer events, maybe parenting it breaks the interactability area

#

so after a drag, resetting it could fix it

slender nymph
vast vessel
slender nymph
#

yes, that is exactly what i've already pointed out. you just decided i was being "passive aggressive" and ignored that information

rocky canyon
#

if ur making something change in the editor.. or have different functionallity that is default.. its editor related

winter tinsel
slender nymph
#

show its code

winter tinsel
#

this SHOULD work right?

#

wait let me send the whole thing

slender nymph
#

again, we need to see the actual relevant code to determine if that is the case

#

this includes the Itemscript as well as any other code related to interacting with it

iron steeple
#

is character controller movement based harder than physics based one rn im struggling to do the oncharactercollderhit

rocky canyon
winter tinsel
#

"interacting" just finds the script, and calls the function that runs all the other code

rocky canyon
#

but in that case Rigidbody uses normal OnCollision events

#

so id imagine that being a bit easier.. but OnCharacterCollider.. isnt hard perse

winter tinsel
#

heres the whole thing

slender nymph
#

this is pickupscript not Itemscript

winter tinsel
#

huh

slender nymph
#

wdym "huh"? these are two completely separate components and i asked to see the code for itemscript

iron steeple
#

this is the code rn for the game its confusing since when it hit an invisible hitbox that acts as a boost for the player it doesnt want to run the method

winter tinsel
slender nymph
winter tinsel
#

cause thats where its stored

slender nymph
#

that code is 100% pointless though

winter tinsel
#

okay, ill delete it after we fix all this

winter tinsel
slender nymph
#

you have already assigned itemscript you're just reassigning it to what it is already set to by calling GetComponent on itself

vast vessel
rocky canyon
slender nymph
# winter tinsel oh okay

also you're not even assigning the parent on the instantiated itemscript in your new code, you're doing it on the prefab. or possibly on the itemscript on this pickupscript object, it is unclear how you've got this set up

iron steeple
winter tinsel
slender nymph
slender nymph
rocky canyon
winter tinsel
#

then

#

how do i put it on the instantiated object?

iron steeple
slender nymph
slender nymph
rocky canyon
#

from that screenshot no it wont work... for :

  1. the box collider is disabled
  2. for ~~OnControllerHit ~~or TriggerEnter to work.. 1 of the them need a rigidbody
slender nymph
#

that last bit is incorrect, no rigidbody needed for CC.OnControllerColliderHit

#

that's kind of its whole point. also i don't think it's needed for the CC to send the OnTrigger messages either

rocky canyon
#

if its a trigger volume (where u walk thru it) you might as well use OnTriggerEnter

winter tinsel
slender nymph
#

you need to get a reference to the instantiated itemscript instance

#

this can be accomplished in one of two ways, either call GetComponent on the postfab variable or change the postfab variable to be an itemscript type, and use your itemscript variable as the prefab

iron steeple
winter tinsel
slender nymph
#

the other option is the better option btw

winter tinsel
#

so postfab.getcomponent<itemscript>();?

slender nymph
rocky canyon
iron steeple
#

sorry that im gonna ask this question how do i make it so the hitbox able to phase through again 😦

slender nymph
#

make it a trigger

rocky canyon
#

TriggerEnter only happenes each new time u enter the trigger

iron steeple
rocky canyon
#

you could use a cool-down timer... so it also counts and makes u wait so long before it'l trigger again..
or u can disable the trigger (box collider) and re-enable it later.. different ways to do it tbh

rocky canyon
iron steeple
#

thanks so much

#

man coding in c# is really different layout as unity huh

languid spire
rocky canyon
#

today i learned 🌈 ⭐, well, i've wasted alot of time adding unneeded rigidbodies for a while now

winter tinsel
slender nymph
#

show what you've tried

winter tinsel
#

how do i refrence it

#

if i change postfab to itemscript it wont work, im trying to give itemscript a name somehow but i dont know how exactlyy

#

i know it was something within the parenthesies of the getcomponent thing

slender nymph
#

well postfab is still a GameObject variable so naturally that won't work. you also just throw away your reference to the itemscript on that object because you just call GetComponent but don't store its return value anywhere

slender nymph
rocky canyon
#

ding-dong-ditch of the code world

slender nymph
#

of course none of this is likely to fix the actual issue anyway 🤷‍♂️

winter tinsel
slender nymph
#

is this your first time using c#?

#

or really any programming language for that matter? because you are doing it elsewhere but somehow not comprehending how to do it here.

winter tinsel
#

no its late and im tired and i just want to get this over with

rocky canyon
#

cough itemscript myReference = postfab.GetComponent<itemscript>(); cough

winter tinsel
slender nymph
#

but even still, the other option where you change the type of your postfab variable and just use the existing reference to the itemscript component on the prefab in place of the prefab variable will be so much fucking easier

slender nymph
winter tinsel
#

because autism thats why

rocky canyon
#

you should only be dealing w/ variables you need..
not sure in your case.. but if ur wanting to access a script directly as a variable
theres really no good point in instantiating it as a gameobject and then getcomponenting the script..
when u can instantiate it as the script (and it will spawn the entire object) [then you have the script reference from the getgo]

slender nymph
rocky canyon
#

PTSD i tell ya! ;0

winter tinsel
# slender nymph don't make excuses

i dont wanan do it because i dont feel like its in my comfort zone yet, i like to take everything at my own pace and understand it indepth

#

not that i wont ever learn it

#

just not now

rocky canyon
#

thats fair..

#

just say that then.. lol

winter tinsel
#

additonally im stubborn enough to literally recode my intire game if i learn something new

#

so if i do learn the more effective methods i will change everything lol

slender nymph
#

my dude, it's literally an incredibly simple change. and should be how you are handling all of your prefabs. you are doing unnecessary operations by requiring yourself to use getcomponent, which you seemingly don't even know how ot use anyway. so use the more effective and better option

winter tinsel
#

i will

#

just not rn

#

theres a very good chance ill just change it in like a few days when i do learn that

#

changing types

slender nymph
#

then you better learn how to use getcomponent, since you don't know how to do that now 🤷‍♂️

#

i won't be continuing this conversation any further though. so when you realize you're still having trouble with the instantiated object you will need to post a full description as well as all of the relevant code again so someone else can assist you

winter tinsel
#

ive used get component so many times before my brain just isnt braining rn

#

thanks for the help tho

slender nymph
winter tinsel
#

you only see the mistake not all the other code that works

slender nymph
#

if there's other code that works, why did you not consult that code when you couldn't figure out how to use GetComponent in the code i suggested you use it in?

winter tinsel
#

and i was allready here

rocky canyon
#
    [SerializeField] 
    private ItemScript prefab; //assign ur prefab here like normally.. (altho we declare it as a ItemScript)``` then its just
```cs
  ItemScript itemScript = Instantiate(prefab, transform);
``` now you have a reference to the ItemScript on the prefab u just spawned.. **and** the prefab in the scene.. w/o coding
slender nymph
#

they didn't even need to change the type of the prefab variable, they could have gotten rid of it completely and just changed the type of their "postfab" variable and used their already existing reference to the itemscript component on the prefab that is stored in their itemscript variable

rocky canyon
#

ah true..

#

i was overcomplicating it myself.. making sure it wasn't a castable scenario

#

it'd been easier to know if they pasted their code like normal.. instead I had to retype it out.. and all the lowercase letters werent sitting well w/ my ide 🤣

winter tinsel
slender nymph
rocky canyon
#

nothing wrong w/ taking a break.. come back to it fresh-eyed and bushy-tailed

#

as my parents would say

#

im blind sry

winter tinsel
#

well thanks for the help ig

winter tinsel
#

i removed it, put it back in and im going to remove it now again

#

even though we havent fixed it ill clean up the code so its tidyer, tidier? tydier??

rocky canyon
#

📌 pro-tip: utilize // comments so u dont have to completely remove/add things

winter tinsel
ionic zephyr
#

How can I create a component in which my slots have a Draggable behaviour(dragging and dropping items into other slots) but with different purposes once the object is dropped?. For example, when the item of the slot is dropped on a Hotbar slot , the Hotbar component does the appropiate operations, however if the Item is dropped on an Inventory Slot, then it is the Inventory Manager that should be called

winter tinsel
winter tinsel
ionic zephyr
winter tinsel
#

ill send you the link to a tutorial about making just the inventory then you can figure everything out yourself, hopefully

ionic zephyr
rocky canyon
winter tinsel
#

then thats everything i can give you

ionic zephyr
slender nymph
# ionic zephyr How can I create a component in which my slots have a Draggable behaviour(draggi...

it really depends on what exactly you want those objects to do. if it's pretty much the same thing, then just have the object being dragged perform whatever operations when it is dropped.
Otherwise, i would create a component that has a UnityEvent on it that the dropped object will check for and then invoke that UnityEvent. then whatever holds the component can do whatever it needs to in response to the UnityEvent being invoked

winter tinsel
#

and ctrl+k+u

#

select everything you want and itll auto comment and uncomment

ionic zephyr
rocky canyon
#

its like trying to perfect a kick-boxing finisher move

rich adder
#
public void Something() { //Cannot close the method on single line }
public void Something() { /* Now we can comment single line */ }```
glass totem
#

can anyone one help me with a problem i having on unity i im making a save and load game where i press play my camera, fixed camera angles all work but when i hit save and then quit the game and the camera get locked where it started and doesn't follow player or anything im using cinema machine and clear shot. but i don't know why when i load my game camera locks and i cant move it or anything i don't know if it my code because it works when game start but doesn't when i save and load

slender nymph
#

are you reassigning its follow target?

glass totem
#

Yes

#

@slender nymph it just on load it lock the camera

slender nymph
#

right so if you are reassigning it to something that either does not exist or to null on load then naturally the camera will no longer follow the object it should be following

glass totem
#

Oh

winter tinsel
#

i have a single idea and that is to instantiate the object directly where it should be instead of instantiating and then assigning its parent, but that will probably require that thing boxfriend said so im gonna tackle that tomorrow and change the type or whatever

glass totem
#

@slender nymph so would I add to my game manger load camera certain spot or something like that

slender nymph
#

i have no idea what your code looks like mate, i only made a guess at what the issue could be.

winter tinsel
#

here, use one of the sites

#

!code

eternal falconBOT
winter tinsel
#

click on one of the links, copy paste code, save, copy the link that you get at the top

#

.rs is the country code for republic of serbia

#

im just suprised lol

rich adder
#

I mean.. its short domain

winter tinsel
#

nono like, the balkans isnt really that known for uh good tech

rich adder
#

its a domain, anyone can buy any country domain (ccTLD)

#

I think i have one from congo .cd

winter tinsel
#

just suprised one of the sites for codeposting on the official discord of one of the most popular game-engines is from a country with one of the least developed tech industry

rich adder
#

the server is in Germany

winter tinsel
#

if you knew the irony in that statement lol

#

onion layers worth

rich adder
winter tinsel
#

yeah, balkaners made it, its painfully obvious

rich adder
#

anyway lets keep it ontopic of unity code 😛

winter tinsel
#

yeah

#

wait

#

nvm, i thought serious sam was made in unity, forgor they had their own engine

glass totem
#

@winter tinsel do I post that code in here once I use large code blocks

winter tinsel
#

you go to the site, paste it there and paste the link here

slender nymph
#

share the link that contains the code, yes

winter tinsel
#

after saving

glass totem
#

Ok

#

Never used it before

eternal falconBOT
ionic zephyr
slender nymph
#

make it a UnityEvent that takes a parameter of type List<RaycastResult> if that is the data you need to pass to it

ionic zephyr
#

Can I do Invoke(List<RaycastResults>)?

slender nymph
#

just like any other method you want to pass an argument to, you must pass an actual object. so you'd pass your raycastResults variable not List<RaycastResults>

ionic zephyr
#

but the raycastResults that I pass through the event are assigned in the editor right?

slender nymph
#

huh? what do you mean by that

#

the raycastResults list is populated by the EventSystem.RaycastAll method you call

ionic zephyr
#

If I do a public Event, I have to attach a component in the editor which contains the method I want to run

slender nymph
#

yes, that does not prevent any of what i've said

ionic zephyr
#

but then how can I pass the raycastResults from this component?

slender nymph
#

i just told you . . .

ionic zephyr
#

thanks for your help and sorry for the confusion!

brazen jolt
#

I want to move a 2d gameobject in a perfect circle, how to do it? Without using parent/child (with script) Tag me please

raw token
#

(among other options)

cosmic dagger
ionic zephyr
#

How can I add a GameObject to a UnityEvent that is attached to a child object of a prefab?

cosmic dagger
ionic zephyr
ionic zephyr
glass totem
raw token
slender nymph
# ionic zephyr What can I do to add it to the event?

instead of having the event on the same object that you are dragging, you should put it on the object you are dropping it on like i suggested earlier. then the dropped object just checks for the component that has the event when it is dropped and invokes the event

ionic zephyr
#

so the method that the event Invokes should be in the object I drop the item on?

#

And the event

slender nymph
#

yes. the event should be on a specific component that your dropped object can check for so it doesn't have to check for those other types of objects that you wanted to run logic on. those other objects will have that component and will just subscribe to the event

ionic zephyr
#

Okay, let me see, thanks again! (dont want to sound annoying)

ionic zephyr
slender nymph
#

why not

ionic zephyr
#

it doesn´t appear

slender nymph
#

is the method public? if not, just add the listener via code

#

also does the event require that type as the parameter

cosmic dagger
ionic zephyr
#

Okay, let me try

cosmic dagger
#

oh, box is already here. listen to them . . .

ionic zephyr
slender nymph
#

i mean exactly what i asked. if you are unsure, then show the relevant code (the method you want to subscribe as well as the declaration of the event)

#

from your previous screenshot when the event was on DraggableItem, the event does not pass any parameter

#

so show that you are using the correct UnityEvent<T> that passes the parameter you expect to pass

ionic zephyr
#

I can´t find the function

slender nymph
#

well you've not shown the actual declaration of the event, but it does appear that it passes 0 parameters. so naturally you won't be able to subscribe a method that expects any more parameters

ionic zephyr
#

public class SlotEventCall : MonoBehaviour
{
public UnityEvent Event;
}

#

this is my declaration

slender nymph
#

exactly, that does not pass any parameters. use the generic UnityEvent with the correct type parameter

ionic zephyr
#

Oh

#

okay, now it finds it

ionic zephyr
#

I can´t reuse this then?

slender nymph
ionic zephyr
slender nymph
#

so you need to pass different information to the two different objects that your draggable object could potentially be dropped on?

ionic zephyr
cosmic dagger
slender nymph
ionic zephyr
slender nymph
#

why? is there a specific reason you cannot use TryGetComponent or GetComponent to check if that component is attached to the object being dropped on?

ionic zephyr
#

a HotbarManager

gloomy jacinth
#

How do I fix my Playfab window not opening/showing?

toxic cove
#

where do I go for like help and shit

slender nymph
slender nymph
eternal falconBOT
slender nymph
ionic zephyr
#

no

slender nymph
#

why

ionic zephyr
#

because it calls a Manager which is a static reference

slender nymph
#

that makes no difference

#

is the hotbar manager not a parent of the hotbar? because if not, that's kind of silly design. make the hotbar manager a parent of the hotbar and you can just GetComponentInParent when you drop the items onto the hotbar instead of relying on the singleton pattern and hoping you dropped it there

slender nymph
#

at this point i'm thinking you did something silly like pass those raycastresults to it because you aren't even doing anything to check if it was dropped on the hotbar until after you invoke the event and the hotbarmanager searches the results for that

ionic zephyr
bright grail
#

I could use some advice. I'm developing a boss rush bullet hell game, and the first boss consists of four shooters. Each shooter uses the same script but is attached to a separate game object. Would it be better to create a single 'BossShooter' script that controls all four shooters from one game object, rather than having separate scripts for each one?

slender nymph
ionic zephyr
slender nymph
#

you don't need to keep saying "static reference" i am aware that the HotbarManager is using the singleton pattern

bright grail
steel stirrup
dense cedar
#

How do I use getComponent if I have multiple game objects of the same type

bright grail
steel stirrup
polar acorn
dense cedar
#

If I have two cameras, how do I get specifically camera two

steel stirrup
#

if you have gameobjects Go1 and Go2, Go1.GetComponent<Collider>() will only return a collider on Go1, it doesn't know or care about Go2

polar acorn
#

GetComponent not required